We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Any ideas why it's impossible to compile that simple code?
#define AB_VALUES 2,3 #define Add(a,b) a+b void main(void) { int c; c = Add (AB_VALUES); }
Yep, The Add macro expects 2 arguments and you only pass one. When you try to do tricky stuff with the preprocessor and you get errors that you can't figure out, you can get the compiler to generate a preprocessor output file (*.i). The option to generate this file is available under the Listing tab in the Project Options dialog. Anyway, the following output is generated for your code:
void main(void) { int c; c = 2,3+ ; #error *** ERROR C307 IN LINE 7 OF main.c: macro 'Add': parameter count mismatch }
"get the compiler to generate a preprocessor output file (*.i)." Hey! - there you go nicking my Top Tips again: http://www.8052.com/forum/read.phtml?id=29152 BTW: the preprocessor output file (*.i) is still a valid 'C' source file; therefore I always add *.i to the list of 'C' source filetypes for my uVision Projects - so then I can view them with syntax colouring! And even compile them, if I want...