C pre-processor for #define

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

C pre-processor for #define

跳至解决方案
1,022 次查看
wba
Contributor III

The C pre-processor in CW 10.3 does not seem to follow the C standards for #define.  It replaces the name that is part of another name.  For example, if I define C1, it will modify MCG_C1.

 

Does anyone know if there is a preference setting that will make it act like satndard C?

标签 (1)
标记 (1)
0 项奖励
1 解答
774 次查看
wba
Contributor III

Pascal, Thanks for replying.

I have found the problem.

I have a #define C1 ...  that I used for a configuration bit.

In MCUinit.c there is a line MCG_C1 = ...

MCG_C1 is a macro that uses C1 which is defined as an element of a structure.

The error that I get is "expected identifier before '(' token".  That didn't tell me anything.

I would have hoped that I would get a warning message if I used a name that was already defined in MKL05Z4.h

Bruce

在原帖中查看解决方案

0 项奖励
7 回复数
774 次查看
wba
Contributor III

Hi Pascal,

I am using the Kinetis MKL05Z8VLC4.

0 项奖励
774 次查看
trytohelp
NXP Employee
NXP Employee

Hi,

I've created an example under MCU V10.4.

I don't reproduced the problem.

C code:

++++++++++++++

#define C1 1

int main(void)

{

       int counter = 0;

      

#if C1

       for(;;) {       

              counter++;

       }

#endif

      

       return 0;

}

++++++++++++++

pre-process file

++++++++++++++

# 1 "<command-line>" 2

# 1 "..\\Sources\\main.c"

# 14 "..\\Sources\\main.c"

int main(void)

{

int counter = 0;

for(;;) {

     counter++;

}

return 0;

}

++++++++++++++

I've checked with the Compiler Preprocess option -DC1 too.

On my side it seems to work fine.

Please can you provide us more details to reproduce the issue?

Pascal

0 项奖励
775 次查看
wba
Contributor III

Pascal, Thanks for replying.

I have found the problem.

I have a #define C1 ...  that I used for a configuration bit.

In MCUinit.c there is a line MCG_C1 = ...

MCG_C1 is a macro that uses C1 which is defined as an element of a structure.

The error that I get is "expected identifier before '(' token".  That didn't tell me anything.

I would have hoped that I would get a warning message if I used a name that was already defined in MKL05Z4.h

Bruce

0 项奖励
774 次查看
trytohelp
NXP Employee
NXP Employee

Hi Bruce,

So problem is solved.

The C1 was already defined in  header file.

Pascal

0 项奖励
774 次查看
trytohelp
NXP Employee
NXP Employee

Hi Bruce,

Are you using GNU or Freescale compiler ?

Pascal

0 项奖励
774 次查看
trytohelp
NXP Employee
NXP Employee

Hi Bruce,

Only GCC compiler is available for this architecture.

I will check it and keep you informed.

Pascal

0 项奖励
774 次查看
trytohelp
NXP Employee
NXP Employee

Hi Bruce,

what is the processor used ?

The MCU V10.3 and V10.4 (last version) are including several archiectures and so different build tool chain.

Regards

Pascal

0 项奖励