Personal tools
You are here: Home Forums R8C/Tiny Structure Initialization

Structure Initialization

Up to R8C/Tiny

Structure Initialization

Posted by Ivan Galicia at September 05. 2008

I 've this structs  definition


typedef struct

{

      byte p;

      byte q;

      byte *msg;

}Ta;


typedef struct

{

     byte m;

     word n;

     Ta oM;

}Tb;

byte t [3] ; 

and create an array of TB's struct and initialize this array in the following way:

const Tb tbArray[1]  = { 1,0xFFFF, {0, 1 , t}};

but the compiler sent me this message : "invalid initializer"

the question : what is the  right way to initialize the array?



Re: Structure Initialization

Posted by Ivan Galicia at September 05. 2008

ok, here is more info...  I was trying to use a variable to initialize the  array

const Tb tbArray[1]  = { 1,0xFFFF, {0, aux , t}};

where aux is  a variable defined in somewhere... so I can't do that

Re: Structure Initialization

Posted by Kadir at September 06. 2008

There is no problem in the first case that you sent.

But in the second one, any compiler will give you an error message. You can only initialize a variable with constants.


So why don't you pass the aux's default value to initial value of tbArray[0].oM.q ?



Re: Structure Initialization

Posted by Grzegorz Mazur at September 07. 2008

Since tbArray is an array, the orthodox way to initialize it would be:

const Tb tbArray[1]  = {{ 1,0xFFFF, {0, 1 , t}}};

Powered by Ploneboard