kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Why use "." in the struct in this way?
@ 2013-07-29 14:56 lx
  2013-07-29 15:20 ` Prashant Shah
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lx @ 2013-07-29 14:56 UTC (permalink / raw)
  To: kernelnewbies

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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130729/b02d656d/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Why use "." in the struct in this way?
  2013-07-29 14:56 Why use "." in the struct in this way? lx
@ 2013-07-29 15:20 ` Prashant Shah
  2013-07-29 15:22 ` Alexandru Juncu
  2013-07-29 15:24 ` Dave Hellewell
  2 siblings, 0 replies; 4+ messages in thread
From: Prashant Shah @ 2013-07-29 15:20 UTC (permalink / raw)
  To: kernelnewbies

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-initialization-syntax

The new specification of C language (C99) allows you to use "tagged"
initializers by supplying the desired member name within the {}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Why use "." in the struct in this way?
  2013-07-29 14:56 Why use "." in the struct in this way? lx
  2013-07-29 15:20 ` Prashant Shah
@ 2013-07-29 15:22 ` Alexandru Juncu
  2013-07-29 15:24 ` Dave Hellewell
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandru Juncu @ 2013-07-29 15:22 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Why use "." in the struct in this way?
  2013-07-29 14:56 Why use "." in the struct in this way? lx
  2013-07-29 15:20 ` Prashant Shah
  2013-07-29 15:22 ` Alexandru Juncu
@ 2013-07-29 15:24 ` Dave Hellewell
  2 siblings, 0 replies; 4+ messages in thread
From: Dave Hellewell @ 2013-07-29 15:24 UTC (permalink / raw)
  To: kernelnewbies

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_initialization

Cheers,

Dave

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-29 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-29 14:56 Why use "." in the struct in this way? lx
2013-07-29 15:20 ` Prashant Shah
2013-07-29 15:22 ` Alexandru Juncu
2013-07-29 15:24 ` Dave Hellewell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).