A comment on aggregate constants
Kevin Martin
kpmartin at watmath.UUCP
Thu Nov 1 04:51:18 AEST 1984
>From mark (mwm at ea.UUCP)
> struct gort {
> int type ;
> union info {
> struct gfloat { float gfx, gfy } ;
> struct gint { long gix, giy } ;
> string *name ;
> } ;
> } sample[] = {
> {T_FLOAT, (struct glfoat) { 3.4, 5.7 } } ,
> {T_INT, (struct gint) { 243, 56 } } ,
> {T_STRING, (char *) "this is a test" }
> } ;
>Comments?
Although I think that aggregate constants are a nice thing in themselves,
I still don't like the name-the-type approach to initualizing unions. I
prefer:
struct gort {
int type ;
union info {
struct gfloat { float gfx, gfy } gfl;
struct gint { long gix, giy } gin;
string *name ;
} ;
} sample[] = {
{T_FLOAT, gfl = { 3.4, 5.7 } } ,
{T_INT, gin = { 243, 56 } } ,
{T_STRING, name = "this is a test" }
} ;
I believe that most C compilers now require you to give names to s/u elements
even if they are themselves s/u elements, so the first two union elements
are improperly declared in the first example.
Kevin Martin, UofW Software Development Group
More information about the Comp.lang.c
mailing list