Uninitialized integers and warnings
Ian Lance Taylor
iant@google.com
Thu Sep 5 19:54:00 GMT 2013
On Wed, Sep 4, 2013 at 10:34 PM, Umesh Kalappa <umesh.kalappa0@gmail.com> wrote:
>>>>When p == 0 the program has undefined behaviour,
> Ian,What makes you to say this is undefined ?,Please can you elaborate more
> on this and again tried with below sample
>
>
> int func (int p)
> {
> int x;
> if (p != 1)
> x = 1;
> return x;
> }
When p == 1 the behaviour of this function is undefined.
C99 6.7.8 p10: "If an object that has automatic storage duration is
not initialized explicitly, its value is indeterminate."
C99 Annex J.2: "The behavior is undefined in the following
circumstances: ... — The value of an object with automatic storage
duration is used while it is indeterminate (6.2.4, 6.7.8, 6.8)."
Let me ask you: what makes you say that the behaviour of this function
is *not* undefined when p == 1?
> Still gcc return with 1 with 03 option and returns some junk with default
> run.Which is inconsistent or Did i missing something here ???
When the behaviour is undefined anything can happen. There is no
meaning to such a program.
Ian
More information about the Gcc
mailing list