We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
"Have you really verified that you have a problem?"
Oh, he/she/it most assuredly has a problem -- the refusal to cut through all of the drivel and obfuscation by simply posting an assembly listing.
**************************************************** IDE-Version: µVision3 V3.50 Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2007
Tool Version Numbers: Toolchain Path: BIN30\ C Compiler: ARM/Thumb C/C++ Compiler, RVCT3.0 [Build 951] for uVision [Full] Assembler: ARM/Thumb Macro Assembler, RVCT3.0 [Build 951] for uVision [Full] Linker/Locator: ARM Linker, RVCT3.0 [Build 951] for uVision [Full] Librarian: ARM Archiver, RVCT3.0 [Build 951] for uVision Hex Converter: ARM FromELF, RVCT3.0 [Build 951] for uVision [Full] CPU DLL: SARM.DLL V3.04 Dialog DLL: DARMP.DLL V1.13 Target DLL: BIN\UL2ARM.DLL V1.26 Dialog DLL: TARMP.DLL V1.11f ******************************************************
would you like? please look at IMPORTANT 17 OPERATOR 17: cmd2.packets = 1000;
****************************************************
#pragma pack(1) 12: { 13: COMMAND2 cmd2; 14: unsigned long Size; 15: 0x000001B0 E24DD008 SUB R13,R13,#0x00000008 16: cmd2.command = 0x01; 0x000001B4 E3A00001 MOV R0,#0x00000001 0x000001B8 E5CD0000 STRB R0,[R13] 17: cmd2.packets = 1000; 0x000001BC E3A00FFA MOV R0,#0x000003E8 0x000001C0 E28DC001 ADD R12,R13,#0x00000001 0x000001C4 E58C0000 STR R0,[R12] 18: Size = cmd2.packets; 0x000001C8 E28DC001 ADD R12,R13,#0x00000001 0x000001CC E59C1000 LDR R1,[R12] 19: Size = cmd2.command; 20: 21: 0x000001D0 E5DD1000 LDRB R1,[R13] 22: } ***************************************************************** if typedef __packed struct { unsigned char command; unsigned long packets; unsigned char reserved[3]; } COMMAND2; 12: { 13: COMMAND2 cmd2; 14: unsigned long Size; 15: 0x000001B0 E92D401C STMDB R13!,{R2-R4,R14} 16: cmd2.command = 0x01; 0x000001B4 E3A00001 MOV R0,#0x00000001 0x000001B8 E5CD0000 STRB R0,[R13] 17: cmd2.packets = 1000; 0x000001BC E28D1001 ADD R1,R13,#0x00000001 0x000001C0 E3A00FFA MOV R0,#0x000003E8 0x000001C4 EB00000E BL 0x00000204 18: Size = cmd2.packets; 0x000001C8 E28D0001 ADD R0,R13,#0x00000001 0x000001CC EB000004 BL 0x000001E4 0x000001D0 E1A04000 MOV R4,R0 19: Size = cmd2.command; 20: 21: 0x000001D4 E5DD4000 LDRB R4,[R13] 22: } ************************************************************************ have no #pragma only for example what must be when compiler will be ignore #pragma 12: { 13: COMMAND2 cmd2; 14: unsigned long Size; 15: 0x000001B0 E24DD00C SUB R13,R13,#0x0000000C 16: cmd2.command = 0x01; 0x000001B4 E3A00001 MOV R0,#0x00000001 0x000001B8 E5CD0000 STRB R0,[R13] 17: cmd2.packets = 1000; 0x000001BC E3A00FFA MOV R0,#0x000003E8 0x000001C0 E58D0004 STR R0,[R13,#0x0004] 18: Size = cmd2.packets; 0x000001C4 E59D1004 LDR R1,[R13,#0x0004] 19: Size = cmd2.command; 20: 21: 0x000001C8 E5DD1000 LDRB R1,[R13] 22: }
if you want - you may add volatile for clear code
if you have no LICENSE - example for evalution version
IDE-Version: µVision3 V3.50 Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2007
Tool Version Numbers: Toolchain Path: BIN30\ C Compiler: ARM/Thumb C/C++ Compiler, RVCT3.0 [Build 951] for uVision [Evaluation] Assembler: ARM/Thumb Macro Assembler, RVCT3.0 [Build 951] for uVision [Evaluation] Linker/Locator: ARM Linker, RVCT3.0 [Build 951] for uVision [Evaluation] Librarian: ARM Archiver, RVCT3.0 [Build 951] for uVision Hex Converter: ARM FromELF, RVCT3.0 [Build 951] for uVision [Evaluation] CPU DLL: SARM.DLL V3.04 Dialog DLL: DARMP.DLL V1.13 Target DLL: BIN\UL2ARM.DLL V1.26 Dialog DLL: TARMP.DLL V1.11f
#pragma pack(1) 12: { 13: COMMAND2 cmd2; 14: volatile unsigned long Size; 15: 0x000001B0 E24DD008 SUB R13,R13,#0x00000008 16: cmd2.command = 0x01; 0x000001B4 E3A00001 MOV R0,#0x00000001 0x000001B8 E5CD0000 STRB R0,[R13] 17: cmd2.packets = 1000; 0x000001BC E3A00FFA MOV R0,#0x000003E8 0x000001C0 E28DC001 ADD R12,R13,#0x00000001 0x000001C4 E58C0000 STR R0,[R12] 18: Size = cmd2.packets; 0x000001C8 E28DC001 ADD R12,R13,#0x00000001 0x000001CC E59C1000 LDR R1,[R12] 19: Size = cmd2.command; 20: 21: 0x000001D0 E5DD1000 LDRB R1,[R13] 22: }
"look at IMPORTANT 17 OPERATOR 17: cmd2.packets = 1000;"
Ah, very good. That wasn't too hard, was it? You have finally shown what the problem is.
For whatever ARM you are using or simulating, read up on how it handles unaligned memory accesses.
"Ah, very good. That wasn't too hard, was it? You have finally shown what the problem is.
For whatever ARM you are using or simulating, read up on how it handles unaligned memory accesses "
are you top manager? who may see - will be see
i finished this topic good bye baby ;-)
"i finished this topic good bye baby"
It is quite unusual to use such terms of endearment in a technical forum, but in case it is the custom where you are from:
Good-bye dear.
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.
SUPER new version have no this problem :-)))
IDE-Version: µVision3 V3.52 Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2007
Tool Version Numbers: Toolchain Path: BIN31\ C Compiler: Armcc.Exe V3.1.0.903 Assembler: Armasm.Exe V3.1.0.903 Linker/Locator: ArmLink.Exe V3.1.0.903 Librarian: ArmAr.Exe V3.1.0.903 Hex Converter: FromElf.Exe V3.1.0.903 CPU DLL: SARM.DLL V3.10 Dialog DLL: DARMP.DLL V1.17 Target DLL: BIN\UL2ARM.DLL V1.30 Dialog DLL: TARMP.DLL V1.17