首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C程序: 为什么printf中的最后一行改为 (&a.i)-(&a) 后,编译就会出错,谁帮小弟我解释说下,多谢

2012-03-31 
C程序: 为什么printf中的最后一行改为 (&a.i)-(&a) 后,编译就会出错,哪位高手帮我解释说下,谢谢。错误提示:

C程序: 为什么printf中的最后一行改为 (&a.i)-(&a) 后,编译就会出错,哪位高手帮我解释说下,谢谢。
错误提示:: error C2230: '-' : indirection to different types

#include "stdio.h"

struct TestStruct1
{
char c1;
short s;
char c2;
int i;
};

void main()
{
struct TestStruct1 a;
printf("c1 %p, s %p, c2 %p, i %p \n",\
(unsigned int)(void *)&a.c1 - (unsigned int)(void *)&a,\
(unsigned int)(void *)&a.s - (unsigned int)(void *)&a,\
(unsigned int)(void *)&a.c2 - (unsigned int)(void *)&a,\
(unsigned int)(void *)&a.i - (unsigned int)(void *)&a); // 为什么这一行改为 (&a.i)-(&a) 就为出错 ???

}


[解决办法]
两个不同的类型,不知道怎么减。

热点排行