structure declaration not supported

Hi ,

While trying to port to Codewarrior environment, i find that the below type of structure declaration is supported only in cygwin/gcc but not in Codewarrior. It breaks in codewarrior environment.

Has anyone come across such a thing and could someone here tell me an equivalent alternative for this so that i can use in codewarrior environment.

struct tfsdev alt_tfsdevtbl[TFSDEVTOT] = { [0 ... (TFSDEVTOT-1)] = { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff } };

char alt_devnames[TFSDEVTOT][TFSNAMESIZE] = { [0 ... (TFSDEVTOT-1)] = { [0 ... (TFSNAMESIZE-1)] = 0xff } };

Regards, Karthik Balaguru

Reply to
karthikbg
Loading thread data ...

Inititalize the struct in a loop. for(p= (char *) alt_tfsdevtbl,i = 0; i < sizeof(alt_tfsdevtbl); i ++) { *p++ = 0xff; }

--
Best Regards,
Ulf Samuelsson
ulf@a-t-m-e-l.com
This message is intended to be my own personal view and it
may or may not be shared by my employer Atmel Nordic AB
Reply to
Ulf Samuelsson

Hi,

There is NO direct replacement in Codewarrior for the structure declaration you are referring to. Although I am not familiar with the Cygwin/gcc compiler you mention, the declaration:

struct tfsdev alt_tfsdevtbl [TFSDEVTOT] = { [0 ... (TFSDEVTOT-1)] = { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff } };

is basically telling the compiler to statically initialize all elements in alt_tfsdevtbl (from 0 to (TFSDEVTOT-1)) to the defaults:

{ (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }

(If I am correct, that means that the tfsdev structure contains 7 "elements/fields").

To make a similar declaration in Codewarrior you must do the following:

struct tfsdev alt_tfsdevtbl [TFSDEVTOT] = { { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,

0xffffffff, 0xffffffff }, //0 { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, //1 { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, //2 ... { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, // TFSDEVTOT-2 { (char *)0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, // TFSDEVTOT-1 };

If TFSDEVTOT is too big, try to encapsulate the initialization in a function:

for ( i = 0; i < TFSDEVTOT; i++ ) { alt_tfsdevtbl [i].xxxxxxx = 0xffffffff; alt_tfsdevtbl [i].xxxxxxx = 0xffffffff; ... OR

memset ( &alt_tfsdevtbl[i], 0xFF, sizeof ( struct tfsdevtbl )); }

Regards Rene Trenado

to karthikbg wrote:

Reply to
rTrenado

Hi, Thx for the info.

Regards, Karthik Balaguru

Reply to
karthikbg

If you read the GCC manual, you'll note that the construct you're using is a GCC extension. Cygwin has nothing to do with this feature.

--

Tauno Voipio
tauno voipio (at) iki fi
Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.