"Declaration does not declare anything" #define 错误

"Declaration does not declare anything" error for #define

我试图将 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;
}

在编译时,我得到了这个错误 -

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;

奇怪的是这段代码在其他机器上也能正常工作。有人可以给我解释一下吗?

预处理器指令后没有分号。

所以这个:

#define ll long long int;

的意思是ll字面意思是long long int;.

那么你的声明:

ll t;

真的是:

long long int; t;

与以下相同:

long long int;
t;

希望现在你能明白为什么你的编译器讨厌它了。


顺便说一句,我知道你在做 "competitive programming [sic]" 并且在那个领域让一切变得简短和不可读是很时髦的,但是如果你想写任何东西,真的要避免像这样的宏接近体面的代码。同样,.