c++使用assert()断言之后,后面的变量所占用的内存是怎么清理的哦?
天蓬老师
天蓬老师 2017-04-17 13:35:55
0
3
608
#include <assert.h>
#include <cstdio>

int main()
{
    int a = 1;
    assert(a < 1 && "wrong here");
    printf("come here\n");
    int b = 2;
    return 0;
}

代码如上。。请问在一段程序中,如果中途使用assert(),然后程序直接中断了,那么在assert后面的那些变量是怎么清理的哦?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
巴扎黑

is not cleaned up, assert actually does not return , and the program is immediately interrupted. After the program is interrupted, the operating system reclaims all resources of this process. In the severe case of the operating system, it is not possible to distinguish between a and What the hell is "wrong here"? It's just a piece of memory.

洪涛

The variables within the

function are all local variables, and the memory of the variable is allocated on the stack. For a,b, the memory of the variable is allocated at the beginning. If you exit normally from the main function, then Normal release. If you exit abnormally directly, there is no need to clean up. .
You can see the difference between exit,return and other functions to exit the program. .

PHPzhong

If assert() is used midway and the program is directly interrupted, how are the variables after assert cleared?

The operating system directly reclaims the memory used by this program.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template