2024-03-28 09:16 PM
Hi,Master:
platform: STM32G070CB
keil ide:
arm Compiler:version 5 (c99 mode)
Question:
#pragma pack(8)
typedef struct{
uint32_t a;
uint8_t b;
uint32_t c;
uint32_t d;
uint32_t e;
} x_t;
#pragma pack()
x_t a[10] = {0};
int sz = sizeof(a[0]);
sz is 20, Why not 24?
Thank you very much!
Solved! Go to Solution.
2024-04-06 11:41 AM - edited 2024-04-06 11:42 AM
The fine manual has the answer.
https://developer.arm.com/documentation/dui0375/g/Compiler-specific-Features/-pragma-pack-n-
"This pragma aligns members of a structure to the minimum of n and their natural alignment."
2024-04-06 01:46 AM
Dear @Lyu.1 ,
Can you please show on the debugger how are packed on memory sz ?
Here is how it works for ARM/Keil for adding padding or not for each variable inside the structure? By default it should be 8 packed .
May be also to know the optimization level used as well , so we can discuss with Keil colleagues .
https://developer.arm.com/documentation/dui0491/i/Compiler-specific-Features/-pragma-pack-n-
Ciao,
STOne-32
2024-04-06 11:41 AM - edited 2024-04-06 11:42 AM
The fine manual has the answer.
https://developer.arm.com/documentation/dui0375/g/Compiler-specific-Features/-pragma-pack-n-
"This pragma aligns members of a structure to the minimum of n and their natural alignment."
2024-04-08 08:07 PM
Thank you for your answer, I understand.
2024-04-08 08:07 PM
Thank you for your answer, I understand.