EmbeddedRelated.com
Forums

Problem with struct and Cosmic compiler

Started by folg...@yahoo.com March 11, 2009
Hello,

I am using cosmic Compiler.
I have this struct:

typedef struct
{
unsigned int IDAC;
unsigned int CANidar0;
unsigned int CANidmr0;
unsigned int CANidar1;
unsigned int CANidmr1;
unsigned int CANidar2;
unsigned int CANidmr2;
unsigned int CANidar3;
unsigned int CANidmr3;
unsigned int CANidar4;
unsigned int CANidmr4;
unsigned int CANidar5;
unsigned int CANidmr5;
unsigned int CANidar6;
unsigned int CANidmr6;
unsigned int CANidar7;
unsigned int CANidmr7;
}FILTER;

Now I wnt to fill the struct like this:
FILTER stConfig;
stConfig {
0x00, 0xFF, // Filter 0
0x00, 0xFF, // Filter 0
0x00, 0xFF, // Filter 1
0x00, 0xFF, // Filter 1
0x00, 0xFF, // Filter 2
0x00, 0xFF, // Filter 2
0x00, 0xFF, // Filter 3
0x00, 0xFF // Filter 3

};

This does not work. I get the error "missing expression" in line "stConfig="

Could anybody tell me, what I am doing wrong?

Best regards
The initialization must be part of the declaration, so simply write:

FILTER stConfig = {
0x00, 0xFF, ...

Best Regards,
Jean-Pierre Lavandier


-----Message d'origine-----
De : 6... [mailto:6...] De la part de
f...@yahoo.com
Envoy: mercredi 11 mars 2009 13:48
: 6...
Objet : [68HC12] Problem with struct and Cosmic compiler

Hello,

I am using cosmic Compiler.
I have this struct:

typedef struct
{
unsigned int IDAC;
unsigned int CANidar0;
unsigned int CANidmr0;
unsigned int CANidar1;
unsigned int CANidmr1;
unsigned int CANidar2;
unsigned int CANidmr2;
unsigned int CANidar3;
unsigned int CANidmr3;
unsigned int CANidar4;
unsigned int CANidmr4;
unsigned int CANidar5;
unsigned int CANidmr5;
unsigned int CANidar6;
unsigned int CANidmr6;
unsigned int CANidar7;
unsigned int CANidmr7;
}FILTER;

Now I wnt to fill the struct like this:
FILTER stConfig;
stConfig=
{
0x00, 0xFF, // Filter 0
0x00, 0xFF, // Filter 0
0x00, 0xFF, // Filter 1
0x00, 0xFF, // Filter 1
0x00, 0xFF, // Filter 2
0x00, 0xFF, // Filter 2
0x00, 0xFF, // Filter 3
0x00, 0xFF // Filter 3

};

This does not work. I get the error "missing expression" in line "stConfig="

Could anybody tell me, what I am doing wrong?

Best regards



The type holds 17 ints. Your instantiation has only 16.

-rob

f...@yahoo.com wrote:
>
> Hello,
>
> I am using cosmic Compiler.
> I have this struct:
>
> typedef struct
> {
> unsigned int IDAC;
> unsigned int CANidar0;
> unsigned int CANidmr0;
> unsigned int CANidar1;
> unsigned int CANidmr1;
> unsigned int CANidar2;
> unsigned int CANidmr2;
> unsigned int CANidar3;
> unsigned int CANidmr3;
> unsigned int CANidar4;
> unsigned int CANidmr4;
> unsigned int CANidar5;
> unsigned int CANidmr5;
> unsigned int CANidar6;
> unsigned int CANidmr6;
> unsigned int CANidar7;
> unsigned int CANidmr7;
> }FILTER;
>
> Now I wnt to fill the struct like this:
> FILTER stConfig;
> stConfig> {
> 0x00, 0xFF, // Filter 0
> 0x00, 0xFF, // Filter 0
> 0x00, 0xFF, // Filter 1
> 0x00, 0xFF, // Filter 1
> 0x00, 0xFF, // Filter 2
> 0x00, 0xFF, // Filter 2
> 0x00, 0xFF, // Filter 3
> 0x00, 0xFF // Filter 3
>
> };
>
> This does not work. I get the error "missing expression" in line
> "stConfig="
>
> Could anybody tell me, what I am doing wrong?
>
> Best regards
Hello,

thank you very much. It works fine now!

Best regards