相关疑难解决方法(0)

"static const"vs"#define"vs"enum"

在C中的以下陈述中哪一个更好用?

static const int var = 5;
Run Code Online (Sandbox Code Playgroud)

要么

#define var 5
Run Code Online (Sandbox Code Playgroud)

要么

enum { var = 5 };
Run Code Online (Sandbox Code Playgroud)

c constants

550
推荐指数
12
解决办法
33万
查看次数

在运行时定义#ifdef

我想在我的程序中使用#ifdef preprocessive指令.我想在运行时定义这个宏(如果我在另一个配置文件中定义这个值会更好,这样我就可以定义它或者在没有编译的情况下随时取消它),所以我不想在make文件中定义它.

我在谷歌搜索过很多相关内容.但我无法得到我想要的确切信息.

有没有办法在运行时定义它.如果是,请善意提出建议.

c runtime conditional-compilation

3
推荐指数
1
解决办法
1359
查看次数

仅在_DEBUG定义时打印:c

我想只在_DEBUG定义时打印信息

#define DEBUG(y) y == true ? #define _DEBUG true  : #define _DEBUG false

#ifdef _DEBUG
#define Print(s)  printf(s); 
#endif
Run Code Online (Sandbox Code Playgroud)

得到错误:

error: '#' is not followed by a macro parameter
Run Code Online (Sandbox Code Playgroud)

有任何建议如何使用预处理器指令实现这一目标?

我打算从我的主要使用它:

DEBUG(true);
Print("Inside main in debug mode");
Run Code Online (Sandbox Code Playgroud)

c preprocessor-directive

0
推荐指数
1
解决办法
1041
查看次数