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


Reply via email to