Mulitple Line Macros in Codewarrior

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mulitple Line Macros in Codewarrior

Jump to solution
2,138 Views
aergin
Contributor I

Hello,

Everytime that I try to compile my code with multiple line macros I get an error:

 

Error  :  C2450: Expected:  ~(IDENT auto const extern registrar static typedef volatile __interrupt

 

The code that it is refering to is:

 

#define PACK8(x,y)       \       
{                               \
  CLEAR8(0, x, 0xff);     \
  PUT8(0, x, y, 0xff);    \
}

 

I have used this same syntax in many other compilers, but I can not get it to compile in Codewarrior for Microcontrollers V6.2.

 

I would greatly appreciate any advice.  Due to the nature of the code, changing these macros to single line ones would not be a desirable solution.

 

Cheers.

Labels (1)
0 Kudos
Reply
1 Solution
853 Views
Lundin
Senior Contributor IV
It would seem that the compiler expects something on the same row as the #define. This seems to solve the problem:

#define PACK8(x,y) { \
  CLEAR8(0, x, 0xff);     \
  PUT8(0, x, y, 0xff);    \
}




What the C standard says, I have no idea.

However, why not write a real function instead? Most modern compilers, including CW, supports inlining, so there is never a reason to use function-like macros.
Message Edited by Lundin on 2009-09-01 03:59 PM

View solution in original post

0 Kudos
Reply
3 Replies
854 Views
Lundin
Senior Contributor IV
It would seem that the compiler expects something on the same row as the #define. This seems to solve the problem:

#define PACK8(x,y) { \
  CLEAR8(0, x, 0xff);     \
  PUT8(0, x, y, 0xff);    \
}




What the C standard says, I have no idea.

However, why not write a real function instead? Most modern compilers, including CW, supports inlining, so there is never a reason to use function-like macros.
Message Edited by Lundin on 2009-09-01 03:59 PM
0 Kudos
Reply
854 Views
aergin
Contributor I
Thanks for the reply.  I do agree that there are better ways to write it.  The problem is, I am locked into auto generated code that comes out in the form I posted.  It is strange that the compiler has a problem with it.  I have been checking to see if I can find a flag or any other setting that will let it go as is.  If I have to manually change all the auto generated code, it could take a long time and then it would have to be redone on regeneation. 
0 Kudos
Reply
854 Views
CompilerGuru
NXP Employee
NXP Employee

Maybe a space problem?

The initial line in the initial post has some spaces after the backward slash character:

With quotes around the string:

"#define PACK8(x,y)       \       "

 

The \ must be the last character on the line, if it is followed by a space then the slash just escapes the space.

 

For such errors I would always have a look at the preprocessor output.

 

Daniel

0 Kudos
Reply