Page 3 of 3

Re: Using compiler features vs "the hard way"

Posted: Fri Mar 16, 2012 2:55 am
by Solar
Fanael wrote:Still, Solar mentioned both Clang and LLVM as if they were distinct compilers.
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.

Re: Using compiler features vs "the hard way"

Posted: Fri Mar 16, 2012 10:22 am
by Civillian
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));
}