Named fields in Structure Initialization

Peter Dufault dufault at
Sat Aug 11 17:05:23 UTC 2012

On Aug 10, 2012, at 16:12 , Gedare Bloom wrote:

> These are called "designated initializers" c.f.
> They don't work for headers that are included from C++ code; i.e. C++ does not compile them properly. That is one concern I know about. But for a plain C file they should be OK to use.

That is my concern also, people start to see that and begin putting them in headers.  They are in the Freescale headers for the MPC55XX, and caused me some pain in the past.

The only use in a header I can think of is to define const initializers that have a unique name that are in global scope.  I suppose that can be replaced with:

extern const struct structure_tag initializer_for_stated_purpose;

and then initializer_for_stated_purpose can be placed in its own "C" file, though you now have to look in that C file to double check that it is really set up as its name describes it, and I suppose that short-circuits optimization also.

Peter Dufault
HD Associates, Inc.      Software and System Engineering

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the devel mailing list