Data Structure problem in Code warrior

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

Data Structure problem in Code warrior

Jump to solution
5,362 Views
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"
Labels (1)
Tags (1)
0 Kudos
1 Solution
1,244 Views
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,

 

View solution in original post

0 Kudos
7 Replies
1,244 Views
wheelmonitor
Contributor II

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

thanks for the reply

0 Kudos
1,244 Views
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 Kudos
1,244 Views
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 Kudos
1,244 Views
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 Kudos
1,245 Views
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 Kudos
1,244 Views
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 Kudos
1,244 Views
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 Kudos