Re: structure initialization

David Wragg (dpw@doc.ic.ac.uk)
01 Sep 1998 20:34:15 +0000


rct@gherkin.sa.wlk.com (Bob_Tracy) writes:
> Why not use the scheme that the SCSI driver writers have been using
> for some time? I don't know if it's part of ANSI C or a GNU C
> extension, but it's a neat way to do things: you can associate
> specific initializers with specific structure members in any order
> you wish, and the powers that be can "diddle" the order of structure
> members (as well as add new structure members -- *cough*) however they
> deem fit and you don't get hosed.
> [snip]

As for many other GCC extensions, C9X will add the same facility to C
but in a different way. (The C9X way is usually better thought
through; this is unsurprising since the committee's job is to think
these things through.)

> Scsi_Host_Template driver_template = AHA1542;
>
> #define AHA1542 { proc_dir: &proc_scsi_aha1542, \
> name: "Adaptec 1542", \
> detect: aha1542_detect, \
> command: aha1542_command, \
> queuecommand: aha1542_queuecommand, \
...

The C9X equivalent would be:

#define AHA1542 { .proc_dir = &proc_scsi_aha1542, \
.name = "Adaptec 1542", \
.detect = aha1542_detect, \
.command = aha1542_command, \
.queuecommand = aha1542_queuecommand, \
...

What to do about C9X for the Linux source will be a tricky probem in a
few years time, since it uses quite a few gcc extensions which will be
superseded by C9X. I suppose it mostly depends on how egcs/gcc
handles the transition.

--
Dave Wragg

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html