struct成员的一种初始化方法

struct成员的一种初始化方法

 

 

转自: http://blog.chinaunix.net/u2/82646/showart_1358435.html

 

我: 在VC++6.0中不能使用这种方法, 看来VC的编译器没太按标准

C99用点号。linux kernel 中的冒号是gcc的扩展。
int main()

        Str s = {.a = 1, .b = 2};//注意这里的点 
        printf("a=%d/nb=%d/n",s.a,s.b);
}
 
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 *);
};

你可能感兴趣的:(struct,ext,delete,编译器,linux内核,filesystems)