Using compiler features vs "the hard way"

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Using compiler features vs "the hard way"

Post 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.
Every good solution is obvious once you've found it.
User avatar
Civillian
Member
Member
Posts: 32
Joined: Tue Feb 21, 2012 3:26 pm

Re: Using compiler features vs "the hard way"

Post 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));
}
Post Reply