[Issue 1626] bool spec problem
Derek Parnell
derek at nomail.afraid.org
Mon Oct 29 20:39:06 PDT 2007
On Tue, 30 Oct 2007 01:16:20 +0000 (UTC), d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1626
>
> davidl at 126.com changed:
>
> What |Removed |Added
> ----------------------------------------------------------------------------
> Status|RESOLVED |REOPENED
> Resolution|INVALID |
>
> ------- Comment #2 from davidl at 126.com 2007-10-29 20:16 -------
> I think you miss the point
> if( 3 )
> {
> }
> works
> And in the spec:
> "Expression is evaluated and must have a type that can be converted to a
> boolean. If it's true the ThenStatement is transferred to"
>
> Notice: If it's *true* the ThenStatement is transferred to
> So what's *true*? I would think the evaluated result of the specific
> expression.
> And what type can have value *true*? bool is the answer.
>
> Therefore, the expression is not only a type that *can* be converted to a
> boolean, but also a type already be converted to a boolean. So the convertion
> here is implicitly.
I think that the confusion comes about because the form...
if (X)
where X does not contain a comparison operand, is really shorthand for ...
if (X != 0)
so the expression is already a boolean so no conversion is needed. That is
to say "if (3 != 0)" returns a boolean already so its not a case of '3'
being converted to a boolean at all.
To repeat, "if (X)" is equivalent to "if (X !=0)" and is not equivalent to
"if (cast(bool)X)".
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
30/10/2007 2:33:56 PM
More information about the Digitalmars-d-bugs
mailing list