【发布时间】:2021-03-30 10:10:15
【问题描述】:
我想通过 c++ 预处理器将elif 作为else if 的宏
所以不要像这样写:-
if (something)
{
// Do something
}
else if (something else)
{
// Do something else
}
else
{
// Do something else
}
我可以这样写:-
if (something)
{
// Do something
}
elif (something else)
{
// Do something else
}
else
{
// Do something else
}
这是我尝试过的:-
#define elif "else if"
但 MinGW-w64 显示错误:-
error: expression cannot be used as a function
请帮忙!?
【问题讨论】:
-
您要解决的问题是什么?
else if对 C 程序员来说太易读了,所以你需要找到一种方法来降低你的代码的可读性,或者......? -
@Lundin 我认为
elif看起来比else if更好(来自python 背景)。此外,我的程序大多是私人的 -
Paul Ogilvie 和@IWonderWhatThisAPI感谢这有效,我以前从未使用过#define,只是看到一些 youtuber 使用引号,所以我也使用了,
-
我会强烈建议不要这样做,即使你是唯一会阅读你的代码的人。改掉坏习惯很难,写只有你懂的代码是个很坏的习惯
标签: c c-preprocessor preprocessor-directive