Thread overview
Is it a bug?
Mar 07, 2005
Andrew Fedoniouk
Mar 07, 2005
Derek Parnell
Mar 17, 2005
Thomas Kuehne
Mar 17, 2005
Derek Parnell
Mar 07, 2005
zwang
Mar 07, 2005
Nick
March 07, 2005
<d>
bool b() { return true; }
bool quit;
if( quit = b() ) // <---------
    return 0;
</d>

DMD 0.114 reports:
.\test.d(17): '=' does not give a boolean result

I understand the intention but statement
does have boolean result.

Am I on the right side?

Andrew Fedoniouk.






March 07, 2005
On Sun, 6 Mar 2005 17:24:12 -0800, Andrew Fedoniouk wrote:

> <d>
> bool b() { return true; }
> bool quit;
> if( quit = b() ) // <---------
>     return 0;
> </d>
> 
> DMD 0.114 reports:
> .\test.d(17): '=' does not give a boolean result
> 

Just a comment, but you can fix this the long way ...

#  if( (quit = b()) == true  )

or the short way ...

#  if( 0, quit = b() )

-- 
Derek
Melbourne, Australia
7/03/2005 12:45:27 PM
March 07, 2005
This is a very annoying "feature" of dmd -- a blatant discrimination of <AssignExpression>!


Andrew Fedoniouk wrote:
> <d>
> bool b() { return true; }
> bool quit;
> if( quit = b() ) // <---------
>     return 0;
> </d>
> 
> DMD 0.114 reports:
> .\test.d(17): '=' does not give a boolean result
> 
> I understand the intention but statement
> does have boolean result.
> 
> Am I on the right side?
> 
> Andrew Fedoniouk.
March 07, 2005
Personally I like the feature, just not the error message, which, as Andrew demonstrates, claims something that is clearly not true.

Nick

In article <d0ggi4$1b9v$1@digitaldaemon.com>, zwang says...
>
>This is a very annoying "feature" of dmd -- a blatant discrimination of <AssignExpression>!
>
>
>Andrew Fedoniouk wrote:
>> <d>
>> bool b() { return true; }
>> bool quit;
>> if( quit = b() ) // <---------
>>     return 0;
>> </d>
>> 
>> DMD 0.114 reports:
>> .\test.d(17): '=' does not give a boolean result
>> 
>> I understand the intention but statement
>> does have boolean result.
>> 
>> Am I on the right side?
>> 
>> Andrew Fedoniouk.


March 07, 2005
Nick wrote:

>>>>.\test.d(17): '=' does not give a boolean result

>>This is a very annoying "feature" of dmd -- a blatant discrimination of <AssignExpression>!

> Personally I like the feature, just not the error message, which, as Andrew
> demonstrates, claims something that is clearly not true.

As long as 'true' is an integer 1, it's actually somewhat correct ;-)

And you should almost always write those "if" expressions out anyway...
If not by using two statements, then at least with an extra parenthesis.

--anders
March 17, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Derek Parnell schrieb am Mon, 7 Mar 2005 12:45:51 +1100:
> On Sun, 6 Mar 2005 17:24:12 -0800, Andrew Fedoniouk wrote:
>
>> <d>
>> bool b() { return true; }
>> bool quit;
>> if( quit = b() ) // <---------
>>     return 0;
>> </d>
>> 
>> DMD 0.114 reports:
>> .\test.d(17): '=' does not give a boolean result
>> 
>
> Just a comment, but you can fix this the long way ...
>
> #  if( (quit = b()) == true  )
>
> or the short way ...
>
> #  if( 0, quit = b() )

Where is this use of "," documented?

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFCOaIh3w+/yD4P9tIRAsMGAJsG5CLaiVIfC9Ud3OppNXec5h/MnQCeOmYC
7jpaCW5NEMg++MBnJbIOab0=
=l6yg
-----END PGP SIGNATURE-----
March 17, 2005
Thomas Kuehne wrote:

>>Just a comment, but you can fix this the long way ...
>>
>>#  if( (quit = b()) == true  )
>>
>>or the short way ...
>>
>>#  if( 0, quit = b() )
> 
> Where is this use of "," documented?

http://www.digitalmars.com/d/expression.html#Expression
> The left operand of the , is evaluated, then the right operand is
> evaluated. The type of the expression is the type of the right operand,
> and the result is the result of the right operand.

The "short" usage above is more like... gross, though ? :-)

--anders
March 17, 2005
On Thu, 17 Mar 2005 16:32:16 +0100, Anders F Björklund wrote:

> Thomas Kuehne wrote:
> 
>>>Just a comment, but you can fix this the long way ...
>>>
>>>#  if( (quit = b()) == true  )
>>>
>>>or the short way ...
>>>
>>>#  if( 0, quit = b() )
>> 
>> Where is this use of "," documented?
> 
> http://www.digitalmars.com/d/expression.html#Expression
>> The left operand of the , is evaluated, then the right operand is evaluated. The type of the expression is the type of the right operand, and the result is the result of the right operand.
> 
> The "short" usage above is more like... gross, though ? :-)
> 

Oh absolutely. I'd shoot anyone in my teams who'd try to get away with
that. I just wanted to highlight that DMD is not catching all the possible
ways you can (ab)use the 'if (A = B)' idiom.

-- 
Derek Parnell
Melbourne, Australia
18/03/2005 7:50:41 AM