Data Structure problem in Code warrior

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

Data Structure problem in Code warrior

跳至解决方案
5,364 次查看
wheelmonitor
Contributor II
Does anyone know if Code Warrior has a problem of declaring data structure within a data structure, In specific i am doing the following and the code warrios is giving me compile error. Anyone has any idea on how to get around the problem:
 
struct{
int x;
int y;
}DATA;
 
typedef struct{
int j;
int k;
DATA d;
}STRUCT;
 
the error i get is "typedef name expected"
标签 (1)
标记 (1)
0 项奖励
1 解答
1,246 次查看
wheelmonitor
Contributor II

you are not going to beleive what the problem was. if you declare DATA after the structure you are using it in it doesn't compile and gives you all sort of errors but if you declare DATA before u use it in another data structure, it complies with no problem.

Thanks for your help

sincerely,

 

在原帖中查看解决方案

0 项奖励
7 回复数
1,246 次查看
wheelmonitor
Contributor II

sorry that was a typo. i did use typedef in front of both structures.

thanks for the reply

0 项奖励
1,246 次查看
CrasyCat
Specialist III

Hello

This should work.

Which processor are you targeting (HC08, HC12, Coldfire, PowerPC, .....)?

Which version of CodeWarrior are you using?
To retrieve version information:
  - Start IDE
  - Select "Help" -> "About Metrowerks CodeWarrior" or "About Freescale CodeWarrior"
  - Press the "Installed Products" button
  - You will see the CodeWarrior version number on top of the "Installed product" dialog.

CrasyCat 

0 项奖励
1,246 次查看
wheelmonitor
Contributor II

hi

i am targetting freescale HC12(MC9S12D64)  and the Code warrior version is 3.0 with IDE version number is 5.5.1272.

Could it be something in the compiler options that i need to look at???

thanks for replying

 

0 项奖励
1,246 次查看
CrasyCat
Specialist III

Hello

There should be something in your application.

I have created a project with CodeWarrior HC12 V3.0 and added following code there.

typedef struct{
int x;
int y;
}DATA;
 
typedef struct{
int j;
int k;
DATA d;
}STRUCT;

STRUCT myStruct;

void main(void) {
  /* put your own code here */
  EnableInterrupts;
  myStruct.j= 9;
  for(;:smileywink: {} /* wait forever */
}

I can build that without any problem.

You may have a syntax error right before the type definition for DATA. Anyway I would need to look at the preprocessor output of the file generating the message.

Can you generate that preprocessor listing (just add option -lp to your compiler command line. The compiler will generate a file with extension .pre. That is the file I need).

CrasyCat

0 项奖励
1,247 次查看
wheelmonitor
Contributor II

you are not going to beleive what the problem was. if you declare DATA after the structure you are using it in it doesn't compile and gives you all sort of errors but if you declare DATA before u use it in another data structure, it complies with no problem.

Thanks for your help

sincerely,

 

0 项奖励
1,246 次查看
CrasyCat
Specialist III

Hello

This is compliant to ANSI C standard :smileywink:.

If type DATA is not known when STRUCT is defined, the compiler cannot evaluate the size of the type STRUCT. So it complains.

CrasyCat

0 项奖励
1,246 次查看
CompilerGuru
NXP Employee
NXP Employee
you missed the typedef before the first declaration.
Therefore this defines a global struct DATA, DATA is not a type, it a variable!
Daniel
0 项奖励