On Sunday 15 January 2006 10:35, Robert Dewar wrote:
> >- I believe that it is a grave mistake to conclude that a well defined
> >  semantic operation on an indeterminate value, has undefined semantics.
>
> Well the standards committee made the grave mistake if it is one, so if
> you want to challenge this, take it up with the standards committee

Actually the C99 standard is rather vague about the behavior if an
object with an indeterminate value is used.  C89 simply states that
this is undefined behavior, but no such explicit statement exists
in C99, at least not as far as I can tell.

Let me quote Dave's program so we know what we're talking about:


typedef long
(*bla)(int *node);

static long F2(void *tree, long blk, bla after_node_func)
{
 long call_result = 0;
 int *node;


 if (call_result = after_node_func(node))
  goto error_free_node;

 T(node);
 return 0;

error_free_node:
 T(node);
error:
 return call_result;
}

long F1(void *tree)
{
 return F2(tree, F3(tree), (void *)0);
}


Note how the automatic variable "int *node" is used but never assigned
a value, i.e. it is not initialized.

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".
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."
3) the C99 standard says nothing about what happens if you use an
   indeterminate value, i.e. the C99 standard imposes no requirements
   on the behavior of a program when an indeterminate value is used.
4) quoting 3.4.3, "undefined behavior" is defined as "behavior, upon
   use of a nonportable or erroneous program construct or of erroneous
   data, for which this International Standard imposes no requirements"


A more explicit statement about using uninitialized variables is in
appendix J.2 ("Undefined behavior"): 

"The behavior is undefined in the following circumstances:
(...snip...)
- The value of an object with automatic storage duration is used
  while it is indeterminate (6.2.4, 6.7.8, 6.8)."

I have added Joseph to the CC:, maybe he can clarify things for us...

Gr.
Steven

Reply via email to