【发布时间】:2015-09-15 01:49:02
【问题描述】:
我试图实现这个问题中给出的内容。sizeof implementation
#include <stdio.h>
#include <stdint.h>
#define my_sizeof(type) ((char*)(&type + 1)-(char*)(&type))
int main()
{
printf("Size of int %d \n",my_sizeof(int));
return 0;
}
但是当我编译时出现以下错误。
test.c:10:44: error: expected expression before ‘int’
printf("Size of int %d \n",my_sizeof(int));
^
test.c:5:35: note: in definition of macro ‘my_sizeof’
#define my_sizeof(type) ((char*)(&type + 1)-(char*)(&type))
^
test.c:10:44: error: expected expression before ‘int’
printf("Size of int %d \n",my_sizeof(int));
^
test.c:5:54: note: in definition of macro ‘my_sizeof’
#define my_sizeof(type) ((char*)(&type + 1)-(char*)(&type))
^
【问题讨论】:
-
那扩展为
((char*)(&int + 1)-(char*)(&int))int的地址是什么?打败我...