c语言struct的一种初始化方法
在linux的内核代码中几乎都是用这种方法的
#include <stdio.h>
typedef struct str
{
int a;
int b;
char name[20];
}Str;
int main()
{
Str s={a:1,b:2,name:"xiangdong"};//注意这里的冒号
printf("a=%d\nb=%d\nname=%s\n",s.a,s.b,s.name);
}
原文是在linux内核2.4.18的linux/fs/ext2/super.c文件里的,如下:
static struct super_operations ext2_sops = {
read_inode: ext2_read_inode,
write_inode: ext2_write_inode,
put_inode: ext2_put_inode,
delete_inode:ext2_delete_inode,
put_super: ext2_put_super,
write_super: ext2_write_super,
statfs: ext2_statfs,
remount_fs: ext2_remount,
};
在linux的内核代码中几乎都是用这种方法的
#include <stdio.h>
typedef struct str
{
int a;
int b;
char name[20];
}Str;
int main()
{
Str s={a:1,b:2,name:"xiangdong"};//注意这里的冒号
printf("a=%d\nb=%d\nname=%s\n",s.a,s.b,s.name);
}
原文是在linux内核2.4.18的linux/fs/ext2/super.c文件里的,如下:
static struct super_operations ext2_sops = {
read_inode: ext2_read_inode,
write_inode: ext2_write_inode,
put_inode: ext2_put_inode,
delete_inode:ext2_delete_inode,
put_super: ext2_put_super,
write_super: ext2_write_super,
statfs: ext2_statfs,
remount_fs: ext2_remount,
};
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/773/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2007-11-21 11:37
评论列表