Brynet-Inc mentioned "Clang/LLVM" as supporting __attribute__. I googled for '"#pragma pack(1)" llvm' and found this bug tracker entry on llvm.org, and I googled '"#pragma pack(1)" clang" and found this, so - being in a hurry and not in a mind for a deep evaluation of compilers - I wrote "Clang and LLVM both support #pragma pack". Blame me for missing the "Product: clang" line in the LLVM bug, or not knowing the relation of Clang and LLVM from personal experience.Fanael wrote:Still, Solar mentioned both Clang and LLVM as if they were distinct compilers.
Using compiler features vs "the hard way"
Re: Using compiler features vs "the hard way"
Every good solution is obvious once you've found it.
Re: Using compiler features vs "the hard way"
I'd say it doesn't look all that bad in code.
Code: Select all
#include <stdio.h>
#pragma pack(1)
typedef struct {
char c;
int i;
} s1_t;
#pragma pack()
typedef struct {
char c;
int i;
} s2_t;
int main(void)
{
printf("sizeof (s1_t):\t%zu\nsizeof (s2_t):\t%zu\n\n", sizeof (s1_t), sizeof (s2_t));
}