-1

How do we force compilers not to have structure padding?Please explain.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Astro
  • 7
  • 1
  • 4

1 Answers1

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)
Community
  • 1
  • 1
R Sahu
  • 204,454
  • 14
  • 159
  • 270