Monday, 15 March 2010

c - Uint16 getting size of 32bit after compiling with GCC -



c - Uint16 getting size of 32bit after compiling with GCC -

i'm quite puzzled next code:

typedef struct { uint16 first:8; // has size of 8 bit uint16 second:8; // has size of 8 bit uint16 third; // has size of 32 bit; what's wrong here? } tsomestruct;

i expected "third" have size of 16 bit instead of 32 bit. i'm sure error must on part.

background: it's not code base of operations , i'm performing verification on it. since it's written embedded scheme , proprietary compiler don't have i'm generating syntax tree "-fdump-translation-unit" alternative , perform verification on that. uint16 should 16 bits long in gcc shouldn't problem, right?

uint16 not standard type in c, size depends on it's typedefed to.

it may typedefed unsigned int because guaranteed 16 bits in proprietary compiler embedded platform. become 32-bit type when compiled current gcc x86 platforms.

is there way forcefulness gcc utilize 16 bits instead of 32 bits int?

i know of none. if have access code, using short instead of int work. if stdint.h available, uint16_t/int16_t work (unless there no 16-bit integer type on platform).

c gcc

No comments:

Post a Comment