linux 内核源码分析 - 获取数组的大小

时间:2014-05-09 02:10:16   收藏:0   阅读:494

 

  

  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))


 

测试程序:

#include<stdio.h> 
#include<stdlib.h>
struct dev
{
	int a;
	char b;
	float c;
};
struct dev devs[]=
{
	{
	    1,‘a‘,7.0,
	},
		{
	    1,‘a‘,7.0,
	},
		{
	    1,‘a‘,7.0,
	},
};
int main()
{
		printf("int  is %d \n" ,sizeof(int));
		printf("char is %d\n",sizeof(char));
		printf("float is %d\n",sizeof(float));
		printf("devs is %d \n",sizeof(devs));
		printf("devs[0] is %d\n",sizeof(devs[0]));
		printf("num is %d \n",sizeof(devs)/sizeof(devs[0]));
		return 0;	
}

 

实践结果如下:

bubuko.com,布布扣

 

linux 内核源码分析 - 获取数组的大小,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!