2022-08-16 03:15 AM
Hello,
Two questions.
First one: __attribute__((__packed__)) does not work: for a structure
typedef __attribute__((__packed__)) struct a_s {
uint32_t M;
uint16_t V;
uint8_t Data[1];
} Type_A;
sizeof(Type_A) returns 8, not 7.
Second one: after STM32CubeIDE update to 1.10.1 when "Build a selected file" (*.c), the file seems to be processed, but NO build results more seen in the CDT Build Console.
Any ideas?
Solved! Go to Solution.
2022-08-17 01:08 AM
Does not work, either.
P.S. Sorry, must revide! Yes, placing the attribute AFTER "}" just before the type name works! sizeof() returns 7.
typedef struct a_s {
uint32_t M;
uint16_t V;
uint8_t Data[1];
} __attribute__((__packed__)) Type_A;
2022-08-16 09:44 AM
2022-08-16 11:19 AM
Maybe try the correct syntax...
An attribute specifier list may appear as part of a struct, union or enum specifier. It may go either immediately after the struct, union or enum keyword, or after the closing brace. The former syntax is preferred.
2022-08-17 12:35 AM
It (struct __attribute__((__packed__)) {... , - placing after struct) does not work either.
2022-08-17 01:08 AM
Does not work, either.
P.S. Sorry, must revide! Yes, placing the attribute AFTER "}" just before the type name works! sizeof() returns 7.
typedef struct a_s {
uint32_t M;
uint16_t V;
uint8_t Data[1];
} __attribute__((__packed__)) Type_A;
2022-08-17 02:41 AM
The "__packed__" attribute name is probably some leftover from old compiler versions and probably is deprecated. The current attribute name is "packed".
2022-08-17 04:34 AM
Both ((packed)) work, when modified according to the thread linked by @Nikita91 above: the __attribute__(()) should be not before or after struct but after } just before the type name:
typedef struct a_s {
uint32_t M;
uint16_t V;
uint8_t Data[1];
} __attribute__((packed)) Type_A;
2022-08-17 01:45 PM
I checked both names of "packed" and both correct attribute positions on GCC v10.3 and all combinations worked.
2022-08-22 06:52 AM
Hello @ColdWeather
For the first question:
I used the same syntax as you but the issue didn't reproduce; sizeof(TypeA) return 8.
typedef __attribute__((__packed__)) struct a_s {
uint32_t M;
uint16_t V;
uint8_t Data[1];
} Type_A;
For the second question:
Check if you are pinning the console view
Does the issue is reproduced with other project in a different workspace.
Kind regards,
Semer.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-08-23 08:22 AM
> both correct attribute positions on GCC v10.3
Yes, gcc understands both variants with underscores and without. This is not new. Haven't checked clang, but gcc is quite an industry standard...
To the OP's question: use static_assert to verify the actual size. (#include <assert.h>)