Click to See Complete Forum and Search --> : Macro Problem


nadz
03-23-2007, 05:54 AM
hi Gurus,

I have this macro which is giving me compile error when I tried to use it
saying missing ')' before '{' when I try to call. Is it not able to recognize for loop? or am I missing something else.
I am using MVC++.

Thanks to all in advance.
nadz

//macro
#define link_list_loop(position, node, head) \
for (position = (head)->next, node = position->next; position != (head); position = node, node = position->next)


// calling
link_list_loop(fix, &PC->OP, node) {
staments.........
}

Danny
03-23-2007, 09:20 AM
you need to remove the spaces in the macro parameter list:
#define link_list_loop(position,node,head) \

in addition, you need to wrap each parameter with parentheses:
#define link_list_loop((position),(node),(head))\

I'm not sure that even after these fixes the code will compile, and as you probably know, macros are best avoided for many good reasons!

nadz
03-23-2007, 09:37 AM
Thank you for replying.
But as you had thought, did not work.

Thanks any ways.
nadz

Danny
03-24-2007, 09:59 AM
The thing is: you can't have spaces anywhere between the macro's components because the space is treated as a replacement. Also, your macro is too complicated syntactically to be parsed safely.

hafsakhan
03-24-2007, 01:43 PM
hi! iam new user of devx thats why i've n't any idea how to communicate with other users as well with councelers all i need is to get the answers of chapter#5 functions which is in book object oriented programming for c++ ?