I think You want something, like union{ int a; struct{ char b; char c }data }x;
On Monday 03 of January 2005 07:16, Venkata, Bulusu (IE10) wrote: > Hi, > I'm having problems with packed structures. Given below is a sample > code("test.c") which uses a packed structure: > > #include <stdio.h> > typedef struct { > char a; > int b; > }__attribute__((packed)) unaligned_struct; > > unaligned_struct hg; > char dummyVar; > > void main(void){ > unaligned_struct* ptr=&hg; > > hg.a = 0x56; > hg.b = 0x1234; > } > > > The equivalent assembly code generated was as follows: > > - 0x1140 <main>: mov #2558, SP ;#0x09fe > - 0x1144 <main+4>: mov r1, r4 ; > 13 unaligned_struct* ptr=&hg; > - 0x1146 <main+6>: mov #514, 0(r4) ;#0x0202 > 14 > 15 hg.a = 0x56; > 0x114c <main+12>: mov.b #86, &0x0202 ;#0x0056 > 16 hg.b = 0x1234; > - 0x1152 <main+18>: mov #4660, &0x0000 ;#0x1234 > - 0x1158 <main+24>: incd SP ; > - 0x115a <main+26>: br #0x115e ; > > The msp430-gcc compiler gives an error/warning at line no. 16, (i.e. at > hg.b = 0x1234;): > test.c:16: internal error: unsupported relocation error > > However, when I tried the same with the IAR compiler, it works fine. I > guess MSPGCC doesn't guarantee support for packed structures due to the > problems MSP430 has with unaligned word accesses - so how does IAR do it? I > apologize for the long post, but I desperately need to use packed > structures in my code. Thank you.. > > Regards, > Sudhakar > > > > ------------------------------------------------------- > The SF.Net email is sponsored by: Beat the post-holiday blues > Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. > It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users