Article View: comp.std.c
Article #2926Re: uninitialized++;
From: Norman Diamond
Date: Wed, 30 Dec 1992 08:39
Date: Wed, 30 Dec 1992 08:39
26 lines
2148 bytes
2148 bytes
In article <9236508.13290@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
>hbf@gandalf.uio.no (Hallvard B Furuseth) writes:
>>Can this fail - on some machine? - in ANSI?
>>main () { int uninitialized; uninitialized++; return 0; }
>I've redirected things to comp.std.c where hopefully someone will be able
I added comp.lang.c back to it so Mr./Ms. Furuseth will find it.
On some machine, yes: if the implementation detects overflow of signed
integers, and uninitialized happens to have started at INT_MAX. And ANSI
Classic section 3.3, page 39 lines 15 to 17, allows failure for this reason:
"If an exception occurs during the evaluation of an expression (that is, if
the result is not mathematically defined or not in the range of representable
values for its type), the behavior is undefined."
On another machine, maybe yes: once upon a time a famous Fortran compiler
helped students catch bugs by checking for things like usings uninitialized
variables. A hypothetical C implementation could try to initialize each
uninitialized object to the worst possible value, in hopes of doing the same.
It would be able to catch yours that way. But consider this program:
main () { int uninitialized; uninitialized += 0; return 0; }
I think this one is not allowed to fail.
--
Norman Diamond diamond@jit.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Pardon me? Or do I have to commit a crime first?
Technical Details
Message-ID:
<C02DDv.2Kw@jrd.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamondReferences:
<HBF.92Dec29211517@gandalf.uio.no> <9236508.13290@mulga.cs.mu.OZ.AU>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c,comp.lang.c Path: arc1-ca.pugleaf.net!sparky!uunet!usc!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond From: diamond@jit533.jit.dec.com (Norman Diamond) Subject: Re: uninitialized++; Message-ID: <C02DDv.2Kw@jrd.dec.com> Sender: usenet@jrd.dec.com (USENET News System) Nntp-Posting-Host: jit533.jit.dec.com Reply-To: diamond@jit.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo References: <HBF.92Dec29211517@gandalf.uio.no> <9236508.13290@mulga.cs.mu.OZ.AU> Date: Wed, 30 Dec 1992 08:39:31 GMT Lines: 26