system 마다 차이가 있지만 기본적으로 메모리 할당은 4Byte 단위로 이루어지기 때문에,

struct 구조체 멤버 변수는 연속된 값을 가지지 못함.

따라서 하기와 같이 해야 1 byte씩 struct 내용을 채울 수 있다

 

#pragma pack(1)

typedef struct customer{
char name;
int height;
int weight;
}customer_type;

 

customer_type kim;

sizeof(kim) ==> 9 byte 크기를 갖음

 

#pragma pack(1)을 선언하지 않으면

#pragma pack(4)를 선언한것 같이 default 인 4byte로 할당되어

 

customer_type kim;

sizeof(kim) ==> 12 byte 크기를 갖음

+ Recent posts