www.digitalmars.com         C & C++   DMDScript  

c++ - value of a condition

reply 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
parent "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])
"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