Data Structure problem in Code warrior

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Data Structure problem in Code warrior

ソリューションへジャンプ
5,961件の閲覧回数
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,843件の閲覧回数
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,843件の閲覧回数
wheelmonitor
Contributor II

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

thanks for the reply

0 件の賞賛
返信
1,843件の閲覧回数
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,843件の閲覧回数
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,843件の閲覧回数
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,844件の閲覧回数
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,843件の閲覧回数
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,843件の閲覧回数
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 件の賞賛
返信