i use keil arm rvct and have small problem RVCT have no #pragma pack(1) but when i got program from my friend i didnt see this program and RVCT didnt say warning about this command - and i have problem because this command destroy execute program for example
#pragma pack(1)
typedef struct { unsigned char command; unsigned long packets; unsigned char reserved[3];
} COMMAND2;
int main() { COMMAND2 cmd2; unsigned long Size;
cmd2.command = 0x01; cmd2.packets = 1000; Size = cmd2.packets; Size = cmd2.command; }
when run this program Size <> 1 at the end !!!
undetermine command #pragma pack(1) create error and compiler dont say warning about this command if correct program for RVTC
typedef __packed struct { unsigned char command; unsigned long packets; unsigned char reserved[3];
we will get ok result
A summary for those who don't want to wade through 22 posts to figure out what the issue here is!!
#pragma pack(1) is not supported by the RVCT compiler according to the compiler manual. The correct way to pack a structure is using the __packed attribute.
As Dan states, the compiler is free to ignore with a warning any pragmas that it doesn't understand.
However the issue here is – as I understand the description – is that the compiler is recognising #pragma pack(1) as a directive to pack the structure with one byte alignment.
It is not however generating the code that will handle accessing the structure in an unaligned way like the code generated when the __packed attribute is used.
If this is true, then Keil support should have a look at this and maybe update the compiler manual or remove this #pragma from the compiler.
"As Dan states, the compiler is free to ignore with a warning any pragmas that it doesn't understand." sorry Dan states - only IGNORE- but i said what compiler MUST WARNING ABOUT IT!!!
YOUR POST IS SUPER POST :-)))) THANK YOU !!!!!!
DEAR Patrick Noonan THANK YOU!!!
I should clarify that an implementation is free to ignore any pragmas that it doesn't recognise. It is not required to issue a warning.
This implementation does issue warnings though for unrecognised pragmas. #pragma pack(1) seems to be special though.
This might just be an omission from the documentation rather than a fault with the compiler though. It remains to be seen.