Thanks for the support guys. :)<div><br></div><div>Unfortunately "halt" would still need to be a keyword if one wants to keep the full behavior of assert(0), where the compiler knows that it affects the control-flow of the program.</div>
<div><br></div><div>Legal:</div><div>int main()</div><div>{</div><div> assert(0);</div><div>}</div><div><br></div><div>Illegal (Error: function D main has no return statement, but is expected to return a value of type int):</div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div>int main()</div><div>{</div><div> int a = 0;</div><div> assert(a);</div><div>}</div><div><br></div><div><br></div><div><div class="gmail_quote">
2010/10/10 Tomek Sowiński <span dir="ltr"><<a href="mailto:just@ask.me">just@ask.me</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Christopher Bergqvist napisał:<br>
<div class="im"><br>
> Hi,<br>
><br>
> Time for some Sunday nitpicking. While reading TDPL, one thing that stuck<br>
> out to me was the special behavior of assert(false). Consider the<br>
> following program compiled with "-release".<br>
><br>
> void main()<br>
> {<br>
> int a = 0;<br>
> assert(a);<br>
> }<br>
><br>
> That program will run without errors. Changing the type of variable a from<br>
> "int" to "enum" results in the program segfaulting thanks to the compiler<br>
> being able to know the value of the expression "a" at compile time and<br>
> inserting a HLT/"halt" instruction. Having the ability to change something<br>
> subtle in a more complex expression or series of expressions without<br>
> realizing you made a compile time assert(false) which crashes your program<br>
> feels ugly.<br>
><br>
</div><div class="im">> I would prefer it if assert() didn't have this special type of behavior,<br>
> and that a "halt" keyword or equivalent was introduced. What do you think?<br>
<br>
</div>I have the same feeling. 'halt' is good, 'fail' is good too. It doesn't have to be a keyword, a<br>
function in object.d would suffice.<br>
<br>
BTW, does anybody know the reason for the assert(0) infernal syntax?<br>
<br>
--<br>
<font color="#888888">Tomek<br>
</font></blockquote></div><br></div>