Topic : (moved) structs and unions

Forum : ST7/STM8

Original Post
Post Information Post
August 13, 2014 - 2:24pm
Raisonance Support Team

(moved from here: http://forum.raisonance.com/viewtopic.php?pid=16262#p16262)

Would anybody happen to know why this doesn't compile? I used it on a PIC compiler before and was ok.

In the .h file:

typedef struct Calibrate_t
{
union
{
struct
{
uint8_t RunCurrent[2];
uint8_t StallCurrent[2];
uint8_t RunTime[2];
uint8_t RunTimeMax[2];
uint8_t StallTimeState[2];
uint8_t ReverseWhenStall;
uint8_t Spare1;
uint8_t Spare2;
};
uint8_t CalibrationArray[13];
};
}Calibrate_t;
extern Calibrate_t calibrate;

In the .c file

Calibrate_t calibrate;

The compiler error i am getting is:

*** ERROR C074 IN LINE 169 OF DATABASE.H : Invalid declaration syntax
*** ERROR C131 IN LINE 184 OF DATABASE.H : unbalanced #if-endif controls

I would like to be able to access the variables in main for example with the following syntax:

Replies
Post Information Post
+1
0
-1
August 13, 2014 - 2:29pm
Raisonance Support Team

Hello,

The first error comes because at the time the structure is compiled, the uint8_t is not (yet) defined.
Please check your includes. You should have a .h file that defines uint8_t and others. Check that you have it and that you include it before defining this struct.

The second error means that you have a #if without a #endif or the opposite. It comes from code that does not appear in your extract so we cannot tell you more. But you must correct it before going further, because it could be the cause of the first error, or it could have the same cause.

If this does not help, we will need a complete project, including source files, headers, etc. for helping you more.

Best Regards,

Raisonance support

+1
0
-1
August 13, 2014 - 11:43pm
Guest

Hi Etienne,

Thanks for getting back to me. I'll remember to put all different posts on a new topic in future :p

I changed all of the "uint8_t" to "unsigned char" and I am still getting same compiler errors.
Also if I comment out the struct decleration in the .c and .h it compiles fine, so I think i have got my #if & #endif correctly bounded.

Can I send a zipped up package of my project to "etienne.cassin@raisonance.com" ?

typedef struct
{
union
{
struct
{
unsigned char RunCurrent[2];
unsigned char StallCurrent[2];
unsigned char RunTime[2];
unsigned char RunTimeMax[2];
unsigned char StallTimeState[2];
unsigned char ReverseWhenStall;
unsigned char Spare1;
unsigned char Spare2;
};
unsigned char CalibrationArray[13];
};
}Calibrate_t;
extern Calibrate_t calibrate;

+1
0
-1
August 14, 2014 - 9:08am
Raisonance Support Team

Hello,

Please, send your project to .

Best regards,