hi all: why use the struct in this way by "." for example, *.owner* instead of *owner* , why? Thank you. 1203 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1203> static struct file_system_type <http://lxr.oss.org.cn/ident?v=2.6.16;i=file_system_type> ext2_fs_type <http://lxr.oss.org.cn/ident?v=2.6.16;i=ext2_fs_type> = {1204 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1204> .owner = THIS_MODULE <http://lxr.oss.org.cn/ident?v=2.6.16;i=THIS_MODULE>,1205 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1205> .name <http://lxr.oss.org.cn/ident?v=2.6.16;i=name> = *"ext2"*,1206 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1206> .get_sb <http://lxr.oss.org.cn/ident?v=2.6.16;i=get_sb> = ext2_get_sb <http://lxr.oss.org.cn/ident?v=2.6.16;i=ext2_get_sb>,1207 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1207> .kill_sb = kill_block_super <http://lxr.oss.org.cn/ident?v=2.6.16;i=kill_block_super>,1208 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1208> .fs_flags = FS_REQUIRES_DEV <http://lxr.oss.org.cn/ident?v=2.6.16;i=FS_REQUIRES_DEV>,1209 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1209> };1210 <http://lxr.oss.org.cn/source/fs/ext2/super.c?v=2.6.16#L1210>
Hi, On Mon, Jul 29, 2013 at 8:26 PM, lx <lxlenovostar@gmail.com> wrote:
hi all: why use the struct in this way by "."
http://stackoverflow.com/questions/3016107/what-is-tagged-structure-initiali... The new specification of C language (C99) allows you to use "tagged" initializers by supplying the desired member name within the {}
On 29 July 2013 17:56, lx <lxlenovostar@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
On 30/07/13 00:56, lx wrote:
hi all: why use the struct in this way by "."
for example, *.owner* instead of *owner* , why?
It's utilising a feature known as designated initialisers. Essentially, using this technique, struct members may be initialised out of order from the way the struct is defined. cf. http://en.wikipedia.org/wiki/Struct_(C_programming_language)#Struct_initiali... Cheers, Dave
participants (4)
-
Alexandru Juncu -
Dave Hellewell -
lx -
Prashant Shah