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++ - value of a condition

↑ ↓ ← Christof Meerwald <cmeerw web.de> writes:
Hi,

According to the C++ standard (6.4 Selection statements [stmt.select]) "the 
value of a condition that is an expression is the value of the expression, 
implicitly converted to bool for statements other than switch". But it seems 
that DM uses the value of the expression implicitly converted to int (the 
following test-case prints "false"):

  #include <stdio.h>

  struct A
  {
    inline operator int()
    {
      return 0;
    }

    inline operator bool()
    {
      return true;
    }
  };


  int main(int argc, char *argv[])
  {
    A a;

    if (a)
    {
      printf("true\n");
      return 0;
    }
    else
    {
      printf("false\n");
      return 1;
    }
  }


bye, Christof
Jan 10 2002
↑ ↓ → "Walter" <walter digitalmars.com> writes:
Ok, I'll get it fixed. Thanks for the great bug reports! -Walter

"Christof Meerwald" <cmeerw web.de> wrote in message
news:a1k5q7$2v33$1 digitaldaemon.com...
 Hi,

 According to the C++ standard (6.4 Selection statements [stmt.select])

 value of a condition that is an expression is the value of the expression,
 implicitly converted to bool for statements other than switch". But it

 that DM uses the value of the expression implicitly converted to int (the
 following test-case prints "false"):

   #include <stdio.h>

   struct A
   {
     inline operator int()
     {
       return 0;
     }

     inline operator bool()
     {
       return true;
     }
   };


   int main(int argc, char *argv[])
   {
     A a;

     if (a)
     {
       printf("true\n");
       return 0;
     }
     else
     {
       printf("false\n");
       return 1;
     }
   }


 bye, Christof

Jan 10 2002