Problem with using && as shorthand for if
div0
div0 at sourceforge.net
Fri Aug 20 13:06:11 PDT 2010
On 20/08/2010 20:59, Ersin Er wrote:
> Hi,
>
> The following code compiles and outputs "1 = 1" as expected:
>
> 1 == 1&& writeln("1 = 1");
>
> However, the following code fails to compile (although it should not):
>
> 1 == 2&& writeln("1 = 2");
>
> The error is as follows:
>
> Error: integral constant must be scalar type, not void
>
> What I expect that the second code should also compile and output nothing when executed.
>
> Am I missing something?
>
> Thanks.
The return type of writeln is void.
You can't && with void.
You are asking
'is X true AND <something which can't return true or false> is true'
which is clearly nonesense.
--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
More information about the Digitalmars-d-learn
mailing list