Article View: comp.std.c
Article #4981Re: Initializing a variable in terms of itself
From: Dan Pop
Date: Tue, 02 Apr 1996 14:29
Date: Tue, 02 Apr 1996 14:29
39 lines
1668 bytes
1668 bytes
In <4jpj9l$ik9@cnn.Princeton.EDU> tim@franck (Tim Hollebeek) writes:
>Just out of curiosity, is this legal?
>
>int main() {
> int x = x;
> return 0;
>}
ANSI classic 1.6:
* Undefined behavior --- behavior, upon use of a nonportable or
erroneous program construct, of erroneous data, or of
indeterminately-valued objects, for which the Standard imposes no
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
requirements. Permissible undefined behavior ranges from ignoring the
situation completely with unpredictable results, to behaving during
translation or program execution in a documented manner characteristic
of the environment (with or without the issuance of a diagnostic
message), to terminating a translation or execution (with the issuance
of a diagnostic message).
ANSI classic 3.5.7:
If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate.
So it's illegal, but a diagnostic isn't required.
>gcc compiles it without even a warning, suprisingly.
Why "suprisingly"? It doesn't complain about i=i++ either.
Dan
--
Dan Pop
CERN, CN Division
Email: danpop@mail.cern.ch
Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
Technical Details
Message-ID:
<danpop.828455346@rscernix>Path:
arc1-ca.pugleaf.net!rcp6.elan.af.mil!rscernix!danpopReferences:
<4jpj9l$ik9@cnn.Princeton.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!rcp6.elan.af.mil!rscernix!danpop Newsgroups: comp.std.c Subject: Re: Initializing a variable in terms of itself Message-ID: <danpop.828455346@rscernix> From: danpop@mail.cern.ch (Dan Pop) Date: 2 Apr 96 14:29:06 GMT References: <4jpj9l$ik9@cnn.Princeton.EDU> Organization: CERN European Lab for Particle Physics NNTP-Posting-Host: ues5.cern.ch X-Newsreader: NN version 6.5.0 #7 (NOV)