On Sun, 10 Oct 2010 19:52:28 +0400, Christopher Bergqvist <[email protected]> wrote:

Hi,

Time for some Sunday nitpicking. While reading TDPL, one thing that stuck
out to me was the special behavior of assert(false). Consider the following
program compiled with "-release".

void main()
{
    int a = 0;
    assert(a);
}

That program will run without errors. Changing the type of variable a from
"int" to "enum" results in the program segfaulting thanks to the compiler
being able to know the value of the expression "a" at compile time and
inserting a HLT/"halt" instruction. Having the ability to change something
subtle in a more complex expression or series of expressions without
realizing you made a compile time assert(false) which crashes your program
feels ugly.

I would prefer it if assert() didn't have this special type of behavior, and
that a "halt" keyword or equivalent was introduced. What do you think?

/ Chris

There is a C abort() function, and most compiler recognize that it doesn't return.

Reply via email to