www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Let the lauding continue ...

↑ ↓ ← "Matthew Wilson" <matthew stlsoft.org> writes:
Another nice one that I can never get any version of VC++ to deal with
correctly

bool    bCorrect     =    true;
int        x;

switch(something)
{
    default:
        bCorrect = false;
        break;
    case ...:
        x = 1;
        break;
    case ...:
        x = 2;
        break;
    case ...:
        x = 3;
        break;
}

if(bCorrect)
{
    y = x; // VC++ warns that x may be used without having been initialised.
Pah!
}

DMC++ (along with others) handles this one nicely
Jun 11 2003
↑ ↓ Heinz Saathoff <hsaat bre.ipnet.de> writes:
Matthew Wilson schrieb...
 Another nice one that I can never get any version of VC++ to deal with
 correctly
 
 bool    bCorrect     =    true;
 int        x;
 
 switch(something)
 {
     default:
         bCorrect = false;
         break;
     case ...:
         x = 1;
         break;
     case ...:
         x = 2;
         break;
     case ...:
         x = 3;
         break;
 }
 
 if(bCorrect)
 {
     y = x; // VC++ warns that x may be used without having been initialised.
 Pah!
 }
 
 DMC++ (along with others) handles this one nicely

In this case it's obvious that x is initialized. But in general it might not be so easy for a compiler to detect this. BTW, some warnings about uninitialized variables are only issued when the files are compiled with optimization enabled. Without optimizations the compiler does not detect these bugs. - Heinz
Jun 12 2003
↑ ↓ → "Walter" <walter digitalmars.com> writes:
"Heinz Saathoff" <hsaat bre.ipnet.de> wrote in message
news:MPG.19524b67e8ac27a99896c2 news.digitalmars.com...
 In this case it's obvious that x is initialized. But in general it might
 not be so easy for a compiler to detect this.

DMC++ only issues the warning if it can prove that the variable is uninitialized, i.e. that there is *no* path that initializes it.
 BTW, some warnings about uninitialized variables are only issued when
 the files are compiled with optimization enabled. Without optimizations
 the compiler does not detect these bugs.

The information to detect this is gathered as a side effect of the optimization process.
Jun 12 2003