Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > uninitialised variable but NO error

Reply
Thread Tools

uninitialised variable but NO error

 
 
geek.arnuld@gmail.com
Guest
Posts: n/a
 
      02-04-2007
this is the programme: [1]

#include <iostream> // std::cout

int main()
{
int sum;
std::cout << sum << "\n";
}


when i compile it using gcc 4.1.2, i get this:

----------------------------------------------------------------------------
[unix@arch cpp]$ g++ first.cpp -o first
[unix@arch cpp]$ ./first
sum is: -1208774992
[unix@arch cpp]$
-----------------------------------------------------------------------------


i think the programme is wrong BUT why this does not give any error
like "uninitialised variable"?



--
http://arnuld.blogspot.com/
Linux registered user #439610
http://counter.li.org/

[1] http://home.no.net/dubjai/win32cpptu..._01_02_02.html

 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      02-04-2007
On Feb 4, 2:01 am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> this is the programme: [1]
>
> #include <iostream> // std::cout
>
> int main()
> {
> int sum;
> std::cout << sum << "\n";
>
> }
>
> when i compile it using gcc 4.1.2, i get this:
>
> ----------------------------------------------------------------------------
> [unix@arch cpp]$ g++ first.cpp -o first
> [unix@arch cpp]$ ./first
> sum is: -1208774992
> [unix@arch cpp]$
> -----------------------------------------------------------------------------
>
> i think the programme is wrong BUT why this does not give any error
> like "uninitialised variable"?


Because its not the compiler's responsability.
It should however generate a warning and you can have the compiler
generate an error instead (with the appropriate options).

>
> --http://arnuld.blogspot.com/
> Linux registered user #439610http://counter.li.org/
>
> [1]http://home.no.net/dubjai/win32cpptut/html/w32cpptut_01_02_02.html



 
Reply With Quote
 
 
 
 
John Ratliff
Guest
Posts: n/a
 
      02-04-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> this is the programme: [1]
>
> #include <iostream> // std::cout
>
> int main()
> {
> int sum;
> std::cout << sum << "\n";
> }
>
>
> when i compile it using gcc 4.1.2, i get this:


If you have more questions about gcc, it would be best to ask them in a
gcc specific newsgroup. This newsgroup is for standard C++ language
questions.

g++ should warn you if you turn on warnings. g++ -W -Wall -O2 first.cpp
gives me a possibly uninitialized warning for your program.

--John Ratliff
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
uninitialised variable but NO error geek.arnuld@gmail.com C++ 2 02-04-2007 11:05 AM
Calling free() on an uninitialised pointer? santosh C Programming 13 12-05-2005 09:05 PM
Uninitialised value error stumping me.. Len Perl Misc 3 02-02-2005 09:06 PM
value of an uninitialised variable Andy Fish XML 7 01-10-2005 04:37 PM
C++: Uninitialised Variable Passed as a Parm Gene Wirchenko C++ 22 12-19-2003 02:26 PM



Advertisments