做了一个实验如下:
void main(void)
{
unsigned short szBuf[10] = {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
unsigned short *sectAddr;
sectAddr = szBuf;
printf("sizeof addr=%d\n", sizeof(*sectAddr));
*(unsigned char *)(sectAddr) = 0x30;
printf("sizeof addr=%d\n", sizeof(*sectAddr));
printf("sizeof addr=%d\n", sizeof(*(unsigned char *)(sectAddr)));
return;
}
显示结果是如下:
sizeof addr=2
sizeof addr=2
sizeof addr=1
这个实验说明了,强制类型转换只是临时有效,使用过后,依然恢复到定义的类型.
阅读(1618) | 评论(0) | 转发(0) |