Which is more common in compilers:

static struct foo foobar = {
        field1: value1,
        field4: value4
        };

OR what's shown below:

static struct foo foobar = {
        .field1 = value1,
        .field4 = value4
        };

The first is used by the kernel code, and has been around for quite a while. I'm not sure what the second form gives us that the first one doesn't. Unless there is a good reason otherwise we should probably stick with the most widely supported.

Walt

Murali Vilayannur wrote:
Hi Pete,
Oops that was my bad..I did not realize that this syntax is not supported
by many compilers! I was once bitten by initializing a struct
incorrectly, and I committed that change since I assumed that a user would
not be able to compile the kmod without having a compiler that understands
that syntax.
Thanks,
Murali

On Mon, 29 May 2006, Pete Wyckoff wrote:


[EMAIL PROTECTED] wrote on Mon, 29 May 2006 10:33 -0400:

Pete Wyckoff wrote:


Another possible way to fix this is by using named initializers,
like

  static union PINT_state_array_values ST_setup_msgpairs[] = {
        { .state_name = "setup_msgpairs" },
        { .parent_machine = &pvfs2_client_small_io_sm },
        { .flag = SM_NONE },
        ...

which would be just dandy, but not all compilers have caught up with
this nice C99-ism.  I didn't want to exclude old compilers, or
support two versions and add a configure check, so rejected this
idea.


I wondered when this became legal -- I love it!  It is already being
used in the distribution code (that is where I learned about it), so I
guess it is okay to begin using everywhere.

Right you are, I had totally forgotten about that usage.  Thus it
seems we have implicitly decided that this feature in a compiler is
mandatory.  I think that rules out ancient things like gcc 2.95 and
some vendor compilers, but that's fine by me.

This new version has my vote:

   struct PINT_state_machine_s pvfs2_client_small_io_sm = {
            .name = "pvfs2_client_small_io_sm",
            .state_machine = ST_setup_msgpairs
   };

   static union PINT_state_array_values ST_setup_msgpairs[] = {
            { .state_name = "setup_msgpairs" },
            { .parent_machine = &pvfs2_client_small_io_sm },
            { .flag = SM_NONE },
            { .state_action = small_io_setup_msgpairs },
            { .return_value = 0 },
            { .next_state = ST_xfer_msgpairs },
            { .return_value = -1 },
            { .flag = SM_RETURN }
   };

Thanks for pointing this out Brad.  I'll commit it in a day or so
unless there are any strong objections.  Diff attached.

                -- Pete


_______________________________________________
Pvfs2-developers mailing list
[email protected]
http://www.beowulf-underground.org/mailman/listinfo/pvfs2-developers

--
Dr. Walter B. Ligon III
Associate Professor
ECE Department
Clemson University
_______________________________________________
Pvfs2-developers mailing list
[email protected]
http://www.beowulf-underground.org/mailman/listinfo/pvfs2-developers

Reply via email to