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 크기를 갖음
'프로그래밍 > VC++ 개발 코딩' 카테고리의 다른 글
VS2010에서 scanf등의 안정성을 위한 warning 무시하기 (0) | 2014.01.17 |
---|---|
메모리 누수, 0xcdcdcdcd 힙, 스택 메모리 초기 default 값. (0) | 2014.01.17 |
VS2010 MFC 변환시 변경점 (0) | 2014.01.17 |
Visual Studio 2003을 비스타 및 Windows 7 에서 쓰기 (0) | 2014.01.17 |
#pragma pack(push, 1), #pragma pack(pop) (0) | 2014.01.17 |