现在的位置: 首页 > 综合 > 正文

关于sizeof在不同平台下的值

2018年04月02日 ⁄ 综合 ⁄ 共 535字 ⁄ 字号 评论关闭

sizeof在不同平台的值并不一样,大家注意下:

/*
	Ubuntu12_x64环境下:
		sizeof()返回值类型是long unsigned int
		sizeof(long) = 8
		sizeof(void) = 1
		sizeof(void*) = 8

	Win7_x64, VC2010环境下(目标机器: 32位):
		sizeof(long) = 4
		sizeof(void) = 0
		sizeof(void*) = 4

	Win7_x64, VC2010环境下(目标机器: 64位):
		sizeof(long) = 4
		sizeof(void) = 0
		sizeof(void*) = 8
*/

#include <string.h>
#include <stdio.h>

int main()
{
	printf("%d\n", sizeof(int));		// 4
	printf("%lu\n", sizeof(long));
	printf("%lu\n", sizeof(float));		// 4
	printf("%lu\n", sizeof(double));	// 8
	printf("%lu\n", sizeof(long long));	// 8
	printf("%lu\n", sizeof(void));
	printf("%lu\n", sizeof(void*));

	return 0;
}

抱歉!评论已关闭.