This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

designated initializers: error or warning for obsolete forms?


Hi,

I've been using designated initializers[1] for structures
for some time, in the form they had been implemented
by the Plan9 C compilers[2], i.e. without a '=' between
designator and initializer, like this:

	Point p = {
		.y	100,
		.x	200
	};

In Ansi-C this now is:
	Point p = {
		.y =	100,
		.x =	200
	};

>From Ansi-C's view there are probably
two obsolete forms, one for array designators,
one for designators in struct initializations,
both without the '='.

Apparently the obsolete form for structs is not supported
anymore since SVN rev 89252 [3] (that for array
designators still is):

	(initelt): Only permit array_designator without '=', not ".foo",

which is the solution to problem report #16667.

In gcc/c-parser.c this is now coded in c_parser_initelt
within the "if (des_seen==1) / else" block -- the else
block generates the error.

Is there a chance that the old behaviour could be
re-enabled, i.e. the error turned into an `obsolete'
warning again? If yes, perhaps it would make sense to
always print that warning, not only if -pedantic), which
would reduce that code to
	  }
	else
	  pedwarn ("obsolete use of designated initializer without %<=%>");

I would find it nice if the old form could be supported
again, as I often use that kind of initialization in
embedded software, and it seems to me that it is a bit
more readable than the Ansi-C version.

Thanks,
Michael

[1] http://www.dmk.com/c/init.html
[2] http://plan9.bell-labs.com/sys/doc/comp.html
[3]
http://gcc.gnu.org/viewcvs/trunk/gcc/c-parse.in?r1=89252&r2=89560&pathrev=95557


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]