Chinaunix首页 | 论坛 | 博客
  • 博客访问: 427329
  • 博文数量: 184
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 594
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-17 16:24
个人简介

我是一只小小鸟

文章分类

全部博文(184)

文章存档

2016年(1)

2015年(55)

2014年(127)

2013年(1)

分类: LINUX

2015-12-04 12:13:11

1 bool布尔型
C++中bool是标准数据类型,单独占1个字节,可取的值为true/false。C中没有bool。如果出现,就是用户自定义的数据类型,可以通过sizeof(bool)来确定bool所占的数据类型。
kernel遇到的实例exp1,定义了多个bool成员在结构DAC960_V2_LogicalDeviceInfo中,成变量名后的 :1表示该成员仅占用1位。也就是说:bool a:1; //只定义变量a占用1位,不非浪费7位

点击(此处)折叠或打开

  1. exp1:
  2. typedef struct DAC960_V2_LogicalDeviceInfo
  3. {
  4. ............................
  5.   /* Logical Device Operations Status */
  6.   bool ConsistencyCheckInProgress:1; /* Byte 9 Bit 0 */
  7.   bool RebuildInProgress:1; /* Byte 9 Bit 1 */
  8.   bool BackgroundInitializationInProgress:1; /* Byte 9 Bit 2 */
  9.   bool ForegroundInitializationInProgress:1; /* Byte 9 Bit 3 */
  10.   bool DataMigrationInProgress:1; /* Byte 9 Bit 4 */
  11.   bool PatrolOperationInProgress:1; /* Byte 9 Bit 5 */
  12.   unsigned char :2; /* Byte 9 Bits 6-7 */
  13.   unsigned char RAID5WriteUpdate; /* Byte 10 */
  14.   unsigned char RAID5Algorithm; /* Byte 11 */
  15.   unsigned short LogicalDeviceNumber; /* Bytes 12-13 */
  16. ..................
  17.   unsigned char Reserved2[64]; /* Bytes 192-255 */
  18. }
  19. DAC960_V2_LogicalDeviceInfo_T;
2 EXPORT_SYMBOL()
EXPORT_SYMBOL有2种应用场景,一种是应用于内核函数符号结构体中,记录函数地址或者函数名称;另一种是导出函数符号,用于保存函数地址和名称。例如分别定义模块1中函数fun1()和模块2中函数fun2()。使用模块2时函数fun2需要调用模块1中的函数fun1,则需要:
在模块1中导出函数:EXPORT_SYMBOL(fun1);
在模块2中:extern int fun1();
这样就可以在模块2/函数fun2中调用fun1了。
exp2:
kmem_cache_create   303  ~/linux/kernel/fork.c:EXPORT_SYMBOL(kmem_cache_create);




阅读(1658) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~