Page 1 of 1

NXC function pointers

Posted: 16 Nov 2010, 19:05
by tobasco666
Hi,
I want to use a menu like the standard menu from NXT 2.0 brick.
Unfortunately I can't find a system call to reuse the existing one :-(

Therefore I tried to implement my own, but it I couldn't declare a function pointer:
typedef struct {
string label;
string ricPath;
bool (*onEnter)(int *item); // compile error
} MenuItem;

Q1:
Doesn't support NXC function pointer at all?
If so, is there any "trick" to deal with something like a callback?
(Sorry if it is a stupid question - I'm not a C developer)

Q2: How can I define struct types which depends on each other ?
typedef struct { B b; } A;
typedef struct { A a; } B;
// In my case: "Menu" contains "MenuItem" and "MenuItem *could* contain a "Menu" (as sub-menu)

Thanks in advance
Thomas

Re: NXC function pointers

Posted: 16 Nov 2010, 20:43
by spillerrec
Not eXactly C is basically C without pointers (and a few other differences). So you can't. (I'm not familiar with function pointers in C though.)

However I think it might be possible in the FW. I'm no expert on the NXT FW bytecode, but I think a variable is used to represent the function, perhaps you could change the value of this variable for interesting results?

Re: NXC function pointers

Posted: 17 Nov 2010, 04:27
by afanofosc
The NXT virtual machine does not support function pointers or recursively defined structures. As a result, neither does NXC.

John Hansen