구조체 형변환 관련해서 질문이 있습니다.

Pike의 이미지

#include <stdio.h>
 
#pragma align 
 
typedef struct Data1
{
	int a1;
	short a2;
	//short a3;
	int a3;
};
 
typedef struct Data2
{
	int b1;
	int b2;
	short b3;
};
 
void main()
{
	Data1 *d1;
	Data2 *d2 = new Data2();
 
	d2->b1 = 1;
	d2->b2 = 131074;
	d2->b3 = 1;
 
	d1 = (Data1*)d2;
 
	printf("%d\n",d1->a2);
	printf("%d\n",d1->a3);
}

여기서 a3의 값이 1이 나오는데요
어제서 a3의 값이 0x00020001이 아니라 1이 될까요?
memcpy를 사용했을때는 값이 0xcccc0001이 나오더군요
0x00020001이 안나오는 이유는 무엇인가요?

pynoos의 이미지

packing 문제로 보이는군요. struct packed attribute 로 검색해보세요.