c++/1561: pointer not initialised to 0

Phil Edwards pedwards@disaster.jaj.com
Sun Apr 1 00:00:00 GMT 2001


The following reply was made to PR c++/1561; it has been noted by GNATS.

From: Phil Edwards <pedwards@disaster.jaj.com>
To: david@davidpashley.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/1561: pointer not initialised to 0
Date: Fri, 5 Jan 2001 12:39:50 -0500

 On Fri, Jan 05, 2001 at 04:06:15PM -0000, david@davidpashley.com wrote:
 > >Description:
 > root% cat c.cc
 > #include <assert.h>
 > 
 >  int *a;
 > 
 >  int main
 >  ()
 >  {
 >      int *b;
 > 
 >      assert (a==0);
 >      assert (b==0);
 > 
 >      exit(0);
 >  }
 > 
 > root% g++ c.cc
 > root% ./a.out 
 > a.out: c.cc:11: int main(): Assertion `b==0' failed.
 > Aborted
 > root% 
 > 
 > I think both the assertions should pass
 
 The C++ standard disagrees with you.  :-)
 
 Local automatic ("stack") variables such as b are not initialized to
 anything.  You must assign a value before using them.
 
 
 Luck++;
 Phil
 
 -- 
 pedwards at disaster dot jaj dot com  |  pme at sources dot redhat dot com
 devphil at several other less interesting addresses in various dot domains
 The gods do not protect fools.  Fools are protected by more capable fools.


More information about the Gcc-prs mailing list