PDA

View Full Version : Macros in C help please



Andrew Davey
04-22-2004, 01:26 AM
I dont knw if anyone can help me but:

Here is my macro:

#define __CALC_CURRENT__ (a,b) ((a) * (b))It basically multiplies a by b.

When calling the macro i use this:

curX = __CALC_CURRENT__(tree->branches[n].dirX, tree->branches[n].length);For some reason and i dont know why i get the following errors:



error C2065: 'a' : undeclared identifier
error C2065: 'b' : undeclared identifier
error C2064: term does not evaluate to a function
error C2064: term does not evaluate to a function
error C2064: term does not evaluate to a functionAnd it all relates to calling the macro.

I have erad the indispensible guide to C part on macros and cant see the problem.

Can someone please help. Thanks.

Relic
04-22-2004, 01:33 AM
Remove the space behind __CALC_CURRENT__ in the definition. :)
Your compiler has expanded the call to
curX = (a,b) ((a) * (b))(tree->branches[n].dirX, tree->branches[n].length);

Andrew Davey
04-22-2004, 01:48 AM
thanks that solved it.

Wohoo it works!!!!!!!!!!!