<div class="gmail_quote">On Fri, Aug 20, 2010 at 23:06, div0 <span dir="ltr"><<a href="mailto:div0@sourceforge.net">div0@sourceforge.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On 20/08/2010 20:59, Ersin Er wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
The following code compiles and outputs "1 = 1" as expected:<br>
<br>
1 == 1&& writeln("1 = 1");<br>
<br>
However, the following code fails to compile (although it should not):<br>
<br>
1 == 2&& writeln("1 = 2");<br>
<br>
The error is as follows:<br>
<br>
Error: integral constant must be scalar type, not void<br>
<br>
What I expect that the second code should also compile and output nothing when executed.<br>
<br>
Am I missing something?<br>
<br>
Thanks.<br>
</blockquote>
<br>
The return type of writeln is void.<br>
You can't && with void.<br>
<br>
You are asking<br>
<br>
'is X true AND <something which can't return true or false> is true'<br>
<br>
which is clearly nonesense.</blockquote><div><br></div><div>Then the first code should not compile too. By the way here is what Andrei wrote in his latest book for the expression a&&b:</div><div><br></div><div>"""</div>
<div><div>* If the type of b is not void, then the expression has type bool. If a is nonzero, the</div><div>expression evaluates b and yields true if and only if b is nonzero. Otherwise, the</div><div>expression evaluates to false.</div>
<div><br></div><div>* If b has type void, the expression has type void as well. If a is nonzero, b is evaluated.</div><div>Otherwise, b is not evaluated.</div></div><div><br></div><div>Using && with a void expression on the right-hand side is useful as shorthand for an</div>
<div>if statement:</div><div><br></div><div>string line;</div><div>...</div><div>line == "#\n" && writeln("Got a # successfully");</div><div>"""</div><div><br></div><div>So I expect my code to compile as well.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888"><br>
-- <br>
My enormous talent is exceeded only by my outrageous laziness.<br>
<a href="http://www.ssTk.co.uk" target="_blank">http://www.ssTk.co.uk</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Ersin ER<div><a href="http://metasolid.com" target="_blank">http://metasolid.com</a></div><br>