🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #272

initialization bug

#272
From: William Ang
Date: Thu, 16 Apr 1992 16:59
24 lines
1048 bytes
g++ version 2.1 running on SunOS 4.1.1.  The initialization of variable
is not correct.

----------------------------------------------------
int main(int argc);
/* here is the problem */
double toprand = pow(2,31) - 1;
/* */
int main(int argc)
{
  cout << "toprand = " << toprand << "\n";
  cout << "toprand = " << pow(2,31) - 1 << "\n";
  return(1);
} 

===========================================================================
RUN

osprey% g++ -O -o testx testx.cc -lm
osprey% testx
toprand = 0                 <--- it should be 2.14748e+09
toprand = 2.14748e+09

Moving the variable declaration inside main() seems to help.
Technical Details
Message-ID: <ANG.92Apr16115900@mockingbird.lcs.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!theory.lcs.mit.edu!ang

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!theory.lcs.mit.edu!ang
From: ang@theory.lcs.mit.edu (William Ang)
Subject: initialization bug
Message-ID: <ANG.92Apr16115900@mockingbird.lcs.mit.edu>
Sender: gnulists@ai.mit.edu
Organization: MIT Lab for Computer Science
Distribution: gnu
Date: Thu, 16 Apr 1992 16:59:00 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 26