Is it possible to solve the align problem with compiler options ?

I am involved again with problems related to alignment. For instance, consider the small code below, where a frame received from ethernet is formatted using a casting operation: ? wBufferSize = recvfrom((char*)bBuffer,MAXCONF_SIZE, saddr_in,sddr_len); SSEConfMarshal psSEConfMarshal = (SSEConfMarshal) bBuffer; switch(psSEConfMarshal->wMethodID) ? In this case, SSEConfMarshal is defined as: typedef STRUCT SEConfMarshal_str { BYTE bVersion; WORD wMethodID; /* WORD = 2 bytes */ BYTE bRevision; BYTE bParameters; } SSEConfMarshal; The code generated by compiler is: SSEConfMarshal psSEConfMarshal = (SSEConfMarshal) bBuffer; e1a02007 MOV R2, R7 switch(psSEConfMarshal->wMethodID) e1d220b2 LDRH R2,[R2,2] Suppose the buffer contents is ?00 ea 03 00 f1 fb 09?. The instruction generated by the compiler (LDRH R2,[R2,2]) will load 0x0300 and not 0xea03 since the offset is 2 ([R2,2]) and not 1 ! Moreover, I imagine if compiler generates ([R2,1]), a misaligned access will take place. What I can I do to solve this problem ? Is it possible to solve the alignment problem with compiler options ?

To modify the alignment, use the #pragma pack(n), where n can be 1, 2, 4, 8, 16. If you enter nothing the alignment get back to 32.

>To modify the alignment, use the #pragma pack(n), > where n can be 1, 2, 4, 8, 16. If you enter nothing > the alignment get back to 32. Yes, I found this pragma only this afternoon :frowning: But it solved all my problems ! Thanks a lot. Marcelo