Re: C question

Galen Seitz <[email protected]>
Newsgroups gmane.comp.gnu.gnucap.devel
Message-ID <[email protected]>
al davis wrote:
> I ran into this in ngspice code ...
> 
> A structure ....
> 
> typedef struct SPICEdev {
>     int (*DEVparam)(int,IFvalue*,GENinstance*,IFvalue *);  
>     int (*DEVmodParam)(int,IFvalue*,GENmodel*);   
>     int (*DEVload)(GENmodel*,CKTcircuit*);   
>     int (*DEVsetup)(SMPmatrix*,GENmodel*,CKTcircuit*,int*);   
> } SPICEdev; 
> 
> is initialized like this ....
> 
> SPICEdev CCCSinfo = {
>     DEVparam      : CCCSparam,
>     DEVmodParam   : NULL,
>     DEVload       : CCCSload,
>     DEVsetup      : CCCSsetup
> };
> 
> I would expect this (as it is in Spice 3f5) ....
> 
> SPICEdev CCCSinfo = {
>     CCCSparam,
>     NULL,
>     CCCSload,
>     CCCSsetup
> };
> 
> 
> The way it is done in ngspice is certainly an improvement, but I 
> could not find any documentation for that syntax.  It obviously 
> works, at least with gcc.  Is this a gcc extension?  Can 
> someone point me to some official documentation?
> 
> I am not looking for an explanation of how this feature works 
> and why to use it.  It is obvious to me.  I am looking for a 
> reference to official documentation. It is a good feature, that 
> I would like to use, but I will only use it if it is part of 
> the official language.

Using a colon in an initializer is an obsolete GCC syntax.  C99
now allows for designated initializers.  See
http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html


In a structure initializer, specify the name of a field to initialize with `.fieldname =' before the element value. For example, given the following structure,

     struct point { int x, y; };

the following initialization

     struct point p = { .y = yvalue, .x = xvalue };

is equivalent to

     struct point p = { xvalue, yvalue };

Another syntax which has the same meaning, obsolete since GCC 2.5, is `fieldname:', as shown here:

     struct point p = { y: yvalue, x: xvalue };


galen
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.