Mulitple Line Macros in Codewarrior

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Mulitple Line Macros in Codewarrior

跳至解决方案
2,768 次查看
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.

标签 (1)
0 项奖励
回复
1 解答
1,483 次查看
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 项奖励
回复
3 回复数
1,484 次查看
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 项奖励
回复
1,484 次查看
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 项奖励
回复
1,484 次查看
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 项奖励
回复