How do we force compilers not to have structure padding?Please explain.
Asked
Active
Viewed 281 times
1 Answers
2
The post What is a "packed" structure in C? addresses how to avoid padding when using gcc.
struct foo __attribute__((__packed__))
{
...
};
The method is same for clang
. See How to declare packed struct (without padding) for LLVM?.
The post at Locally disable padding addresses how to avoid padding when using MS Visual Studio.
#pragma pack(push, 1)
struct foo
{
...
};
#pragma pack(pop)