🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4977

Re: Initializing a variable in terms of itself

#4977
From: James Kanze US/ESC 60/3/141 #407...
Date: Tue, 02 Apr 1996 15:13
21 lines
1225 bytes
In article <4jpj9l$ik9@cnn.Princeton.EDU> tim@franck (Tim Hollebeek)
writes:

|> Just out of curiosity, is this legal?

|> int main() {
|>     int x = x;
|>     return 0;
|> }

No, it is undefined behavior, because you are accessing a variable
before having initialized it.

The reference to `x' in the initialization expression is not, per se,
illegal.  The variable is declared, and available for use, as soon as
the compiler sees the `=' sign.
-- 
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
                -- A la recherche d'une activité dans une region francophone
Technical Details
Message-ID: <KANZE.96Apr2171323@slsvgqt.lts.sel.alcatel.de>
Path: arc1-ca.pugleaf.net!blackbush.xlink.net!slsv6bt!news
References: <4jpj9l$ik9@cnn.Princeton.EDU>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!blackbush.xlink.net!slsv6bt!news
From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Subject: Re: Initializing a variable in terms of itself
In-Reply-To: tim@franck's message of 1 Apr 1996 21:53:57 GMT
Message-ID: <KANZE.96Apr2171323@slsvgqt.lts.sel.alcatel.de>
Sender: news@lts.sel.alcatel.de
Organization: GABI Software, Sarl.
References: <4jpj9l$ik9@cnn.Princeton.EDU>
Date: 02 Apr 1996 15:13:23 GMT