c语言struct的一种初始化方法

typedef struct str
{
    int a;
    int b;
}Str;

int main()
{
    Str s={a:1,b:2};//注意这里的冒号
    printf("a=%d/nb=%d/n",s.a,s.b);
}



原文是在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,
};


super_operations的定义在linux/include/linux/fs.h文件中,原文为:
struct super_operations {
    void (*read_inode) (struct inode *);

    /* reiserfs kludge.  reiserfs needs 64 bits of information to
    ** find an inode.  We are using the read_inode2 call to get
    ** that information.  We don't like this, and are waiting on some
    ** VFS changes for the real solution.
    ** iget4 calls read_inode2, iff it is defined
    */
    void (*read_inode2) (struct inode *, void *) ;
    void (*dirty_inode) (struct inode *);
    void (*write_inode) (struct inode *, int);
    void (*put_inode) (struct inode *);
    void (*delete_inode) (struct inode *);
    void (*put_super) (struct super_block *);
    void (*write_super) (struct super_block *);
    void (*write_super_lockfs) (struct super_block *);
    void (*unlockfs) (struct super_block *);
    int (*statfs) (struct super_block *, struct statfs *);
    int (*remount_fs) (struct super_block *, int *, char *);
    void (*clear_inode) (struct inode *);
    void (*umount_begin) (struct super_block *);

    /* Following are for knfsd to interact with "interesting" filesystems
     * Currently just reiserfs, but possibly FAT and others later
     *
     * fh_to_dentry is given a filehandle fragement with length, and a type flag
     *   and must return a dentry for the referenced object or, if "parent" is
     *   set, a dentry for the parent of the object.
     *   If a dentry cannot be found, a "root" dentry should be created and
     *   flaged as DCACHE_NFSD_DISCONNECTED. nfsd_iget is an example implementation.
     *
     * dentry_to_fh is given a dentry and must generate the filesys  specific
     *   part of the file handle.  Available length is passed in *lenp  and used
     *   length should be returned therein.
     *   If need_parent is set, then dentry_to_fh should encode  sufficient information
     *   to find the (current) parent.
     *   dentry_to_fh should return a 1byte "type" which will be passed  back in
     *   the fhtype arguement to fh_to_dentry.  Type of 0 is reserved.
     *   If filesystem was exportable before the introduction of  fh_to_dentry,
     *   types 1 and 2 should be used is that same way as the generic  code.
     *   Type 255 means error.
     *
     * Lengths are in units of 4bytes, not bytes.
     */
    struct dentry * (*fh_to_dentry)(struct super_block *sb, __u32 *fh,  int len, int fhtype, int parent);
    int (*dentry_to_fh)(struct dentry *, __u32 *fh, int *lenp, int  need_parent);
    int (*show_options)(struct seq_file *, struct vfsmount *);
};

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=591601

<script src="http://writeblog.csdn.net/PromoteIcon.aspx?Id=591601" type="text/javascript"></script> [ 点击此处收藏本文]   发表于 2006年02月04日 11:21 AM

href="http://blog.csdn.net/cacf10/Services/Pingback.aspx" rel="pingback" /> <script type="text/javascript">function hide(){showComment();}</script>
<script type="text/javascript">document.write("");</script>

 

 
Robin Qiu 发表于2006-02-21 4:02 PM  IP: 192.168.10.*
C99用点号。linux kernel 中的冒号是gcc的扩展。
int main()
{
Str s = {.a = 1,
.b = 2};//注意这里的点
printf("a=%d/nb=%d/n",s.a,s.b);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值