I've looked at the draft version of C99 that I have and it's
clear that there are some significant differences between the
draft that I have and the final. So, take what I say with a
grain of salt ;)
> I believe Dave's program results in undefined behavior by implication.
> That is, even though C99 does not appear to be stating anything about
> using indeterminate values in the normative sections, it is implicit
> in the standard, because:
> 1) quoting 3.17.2, an "indeterminate value" is defined as "either
> an unspecified value or a trap representation".
As far as I know, GCC doesn't support a trap representation for
"int *" types. Thus, an "indeterminate value" is simply an unspecified
value.
> 2) according to C99 6.7.8 ("Initialization"), paragraph 10, "If an
> object that has automatic storage duration is not initialized
> explicitly, its value is indeterminate."
I see in C99 6.8.3:
A block allows a set of declarations and statements to be grouped
into one syntatic unit. The initializers of objects that have automatic
storage duration, and the variable length array declarators of ordinary
identifers with block scope, are evaluated and the values are stored
in the objects (including storing an indeterminate value in objects
without an initializer) each time the declaration is reached in the
order of execution, as if it were a statement, and within each
declaration in the order that the declarators occur.
Regarding automatic storage, I see in C99 6.2.4
For such an object that does not have a variable length array type, storage
is guaranteed to be reserved for a new instance of the object on entry
into the block with which it is associated; the initial value of the
object is indeterminate. If an initialization is specified for the
object, it is performed each time the declaration in the execution of
the block; otherwise the value becomes indeterminate each time the
declaration is reached.
and in 5.1.2.3
An instance of each object with automatic storage duration is associated
with each entry into its block. Such an object exists and retains its
last-stored value during the execution of the block and while the block
is suspended (by a call of a function or a receipt of a signal).
This seems pretty clear. C99 requires that storage be allocated
for uninitialized objects, that an indeterminate value be stored
in the object when the declarator for the object is reached in the
block, that the last-stored value be retained for the duration of
the block.
Now, the argument being advanced here is that this is all irrelevant
since the use of an indeterminate value constitutes undefined behavior
and GCC can pretty much do anything. However, "undefined behavior"
is conditional on the standard not imposing requirements on the construct,
data or object. Further, I think the general intent was that
implementations be as portable as possible.
Dave
--
J. David Anglin [EMAIL PROTECTED]
National Research Council of Canada (613) 990-0752 (FAX: 952-6602)