What is the function of this statement *(long*)0=0;?

前端 未结 4 1878
余生分开走
余生分开走 2020-12-13 12:58

In the following code, *(long*)0=0; is used along with the if clause, but what is its purpose?

if(r.wid*r.ht < tot)
    *(long*)         


        
4条回答
  •  半阙折子戏
    2020-12-13 13:58

    To cause a program to 'exit abnormally', use the abort() function (http://pubs.opengroup.org/onlinepubs/9699919799/functions/abort.html).

    The standard C/C++ idiom for "if condition X is not true, make the program exit abnormally" is the assert() macro. The code above would be better written:

    assert( !(r.wid*r.ht < tot) );
    

    or (if you're happy to ignore edge cases), it reads more cleanly as:

    assert( r.wid*r.ht >= tot );
    

提交回复
热议问题