jin*_*dan -2 c++ macros compiler-errors g++ c++14
我试图定义ll为long long. 但是,这没有编译并引发错误。
我在 Windows 机器上使用 VS Code。我也在使用 gcc 8.2.0 版。
这是代码 -
#include <bits/stdc++.h>
using namespace std;
#define ll long long int;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在编译这个时,我收到了这个错误 -
test.cpp: In function 'int main()':
test.cpp:5:22: error: declaration does not declare anything [-fpermissive]
#define ll long long int;
^~~
test.cpp:12:5: note: in expansion of macro 'll'
ll t;
^~
test.cpp:12:8: error: 't' was not declared in this scope
ll t;
^
test.cpp:12:8: note: suggested alternative: 'tm'
ll t;
Run Code Online (Sandbox Code Playgroud)
奇怪的是,这个确切的代码适用于其他机器。有人可以向我解释一下吗?
预处理器指令后没有分号。
所以这:
#define ll long long int;
Run Code Online (Sandbox Code Playgroud)
意思ll是字面意思long long int;。
然后你的声明:
ll t;
Run Code Online (Sandbox Code Playgroud)
是真的:
long long int; t;
Run Code Online (Sandbox Code Playgroud)
这与以下内容相同:
long long int;
t;
Run Code Online (Sandbox Code Playgroud)
希望现在你能明白为什么你的编译器讨厌它。
顺便说一句,我意识到您正在做“竞争性编程[原文如此] ”,并且在该领域使所有内容简短且不可读是很时髦的,但是如果您想编写任何接近体面的代码,确实应该避免使用此类宏. 同样,不要包含实现标头。