Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
预处理器参数和在C中编译#ifndef#ifdef_C_C Preprocessor_Conditional Compilation_Ifndef - Fatal编程技术网

预处理器参数和在C中编译#ifndef#ifdef

预处理器参数和在C中编译#ifndef#ifdef,c,c-preprocessor,conditional-compilation,ifndef,C,C Preprocessor,Conditional Compilation,Ifndef,编译文件时尝试在代码中应用默认值 我需要在代码中将定义的关键字设置为某个值 因此,当我编译代码时,它在编译器的参数中没有收到任何定义,它将使用我的默认值 我不确定该怎么做,但我有一点想法: #ifndef MAXWORKLOAD #define MAXWORKLOAD 10 #endif 因此,如果我将其放在代码中,并在参数中使用此命令行: gcc -W -Wall 它将使用10有默认值吗 如果我在编译时使用此命令行: gcc -W -Wall -DMAXWORKLOAD=5 它将使用5

编译文件时尝试在代码中应用默认值

我需要在代码中将定义的关键字设置为某个值

因此,当我编译代码时,它在编译器的参数中没有收到任何定义,它将使用我的默认值

我不确定该怎么做,但我有一点想法:

#ifndef MAXWORKLOAD
#define MAXWORKLOAD 10
#endif
因此,如果我将其放在代码中,并在参数中使用此命令行:

gcc -W -Wall 
它将使用10有默认值吗

如果我在编译时使用此命令行:

gcc -W -Wall -DMAXWORKLOAD=5
它将使用5作为其新设置


通过阅读有关此问题的文档,我不太清楚。

不确定如何回答此问题,但


是的,没错。

是的。顺便说一句:你为什么不试试呢?