NXC function pointers

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
tobasco666
Posts: 2
Joined: 13 Oct 2010, 09:05

NXC function pointers

Post 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
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC function pointers

Post 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?
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC function pointers

Post by afanofosc »

The NXT virtual machine does not support function pointers or recursively defined structures. As a result, neither does NXC.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 27 guests