| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2662 人关注过本帖
标题:字符设备驱动程序设计中的数据结构:struct file?用法看的迷糊啊
只看楼主 加入收藏
GaFu
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2008-9-4
收藏
 问题点数:0 回复次数:3 
字符设备驱动程序设计中的数据结构:struct file?用法看的迷糊啊
c语言学的不精
struct file_operations mem_fops = {
    .owner = THIS_MODULE,
    .llseek = mem_seek,
    .read = mem_read,
    .write = mem_write,
    .ioctl = mem_ioctl,
    .open = mem_open,
    .release = mem_release,
};
主要是前边的小点,在结构体中这么用什么意思啊(成员变量引用?),前边还有个等号(给结构体赋值?),原定义的file_operations结构体成员变量也不是这样的啊,用的是冒号(:)这在C中不是位定义了吗?
搜索更多相关主题的帖子: 数据结构 程序设计 struct 用法 file 
2008-11-06 13:46
rootkit
Rank: 1
等 级:新手上路
帖 子:197
专家分:5
注 册:2008-9-26
收藏
得分:0 
This declaration uses the standard C tagged structure initialization syntax. This syntax is preferred because it makes drivers more portable across changes in the definitions of the structures and, arguably, makes the code more compact and readable. Tagged initialization allows the reordering of structure members; in some cases, substantial performance improvements have been realized by placing pointers to frequently accessed members in the same hardware cache line.

降妖除魔路,仗剑载酒行
借问谁家子,大唐游侠儿
2008-11-06 20:39
GaFu
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2008-9-4
收藏
得分:0 
楼上,粘的英语解说只说了这样声明结构的好处,还是不明白
2008-11-07 00:34
rootkit
Rank: 1
等 级:新手上路
帖 子:197
专家分:5
注 册:2008-9-26
收藏
得分:0 
The tagged structure initialization syntax allow you to initialize structure member in any order. So your code have no need to be modified  after the change of member definition order. And this feature has been a part of C standard since 1999.

struct file_operations mem_fops = {
    .owner = THIS_MODULE,
    .llseek = mem_seek,
    .read = mem_read,
    .write = mem_write,
    .ioctl = mem_ioctl,
    .open = mem_open,
    .release = mem_release,
};

.owner, .llseek and others are all the member tags.

For example:
struct foo{
int a;
int b;
};

You can declaration and initialize structure variable like this:

struct foo bar{
       .a = 1;
       .b = 2;
};

or in the other order:
struct foo bar{
       .b = 2;
       .a = 1;
};

Have you got it ?

[[it] 本帖最后由 rootkit 于 2008-11-7 15:42 编辑 [/it]]

降妖除魔路,仗剑载酒行
借问谁家子,大唐游侠儿
2008-11-07 15:38
快速回复:字符设备驱动程序设计中的数据结构:struct file?用法看的迷糊啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.058060 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved