Why assert is causing compilation error if I use it before main() call ?
It causes compilation error (Syntax error):
如果我在main()调用之前使用它,为什么assert会导致编译错误?它会导致编译错误(语法错误):
"test.cpp:4:8: error: expected ')' before numeric constant"
“test.cpp:4:8:错误:预期')'在数字常量之前”
#include <stdio.h>
#include <assert.h>
assert(0); //If I comment assert from here, then it compiles fine.
int main()
{
assert(0);
return 0;
}
1 个解决方案
#1
0
You can't call functions from the global scope. That's why.
您无法从全局范围调用函数。这就是为什么。
Move the assert into main
or some other function.
将断言移动到主要或其他功能。
#1
0
You can't call functions from the global scope. That's why.
您无法从全局范围调用函数。这就是为什么。
Move the assert into main
or some other function.
将断言移动到主要或其他功能。