Why use "." in the struct in this way?

Alexandru Juncu alexj at rosedu.org
Mon Jul 29 11:22:02 EDT 2013


On 29 July 2013 17:56, lx <lxlenovostar at gmail.com> wrote:
> hi all:
>        why use the struct in this way by "."
>
> for example, .owner instead of owner , why?
> Thank you.
>
> 1203 static struct file_system_type ext2_fs_type = {
> 1204         .owner          = THIS_MODULE,
> 1205         .name           = "ext2",
> 1206         .get_sb         = ext2_get_sb,
> 1207         .kill_sb        = kill_block_super,
> 1208         .fs_flags       = FS_REQUIRES_DEV,
> 1209 };
> 1210


If you notice the definition of struct file_system_type [1], you will
see that the structure has more fields than you are initiating. In
this case, you just want to refer to some of the fields in the
structure.
You either give all fields a value (in order), or use the .field to
just refer to a single field and set a value for it.

[1] http://lxr.oss.org.cn/source/include/linux/fs.h?v=2.6.16#L1240



More information about the Kernelnewbies mailing list