This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: structure packing
- From: vijay nag <vijunag at gmail dot com>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 16 Jan 2014 16:15:16 +0530
- Subject: RE: structure packing
- Authentication-results: sourceware.org; auth=none
Dear gcc,
Why is the size of below struct UnPackedStruct 6 ? Is there any switch
similar to -E in gcc to check how data alignment is performed by GCC
for structs ?
#include <stdio.h>
#include <stdint.h>
struct tlv_header_t {
unsigned char tlv_length_upper : 3;
unsigned char reserved : 5;
unsigned char tlv_length_lower;
uint16_t tlv_type;
};
typedef struct {
struct tlv_header_t sess;
uint8_t p;
} UnPackedStruct;
typedef struct {
int a;
char b;
} PaddedStruct;
int main()
{
UnPackedStruct a;
PaddedStruct b;
printf("size of a = %u\n", sizeof(a));
printf("size of b = %u\n", sizeof(b));
return 1;
}
./padding
size of a = 6
size of b = 8