C89 includes blocks you know...
Posted Jun 12, 2008 5:17 UTC (Thu) by eru
In reply to: C89 includes blocks you know...
Parent article: Implications of pure and constant functions
Really? Everything I've found, including my reading of the text of C89, seems to say that
initializers of automatic variables must be constant (and I use a number of compilers on a
daily basis that reject non-constant initializers in C89 mode).
Well, they are broken compilers. Complain to the vendor.
A cite from C89 that supports your interpretation would be nice.
From my photocopy the original X3.159-1989:
All the expressions in an initializer for an object that has static
storage duration or in an initializer list for an object that has
aggregate or union type shall be constant
Since the standard does not specify such constantness constraint for
all objects with automatic storage duration, they can be runtime values.
The Rationale section for 3.5.7 makes this even more clear: According to it, the committee even considered allowing automatic aggregate initializers to consist of series of or arbitrary runtime expressions, but did not
go that far in the end. The rationale also mentions that a function call
that returns a structure is permitted as an initializer for an automatic
variable with structure type. I have used some old compilers that had
problems with this kind of structure initialization, but they still
allowed automatic scalars to be initialized with runtime values. I think
even K&R C allowed this.
to post comments)