gpt4 book ai didi

c - 未定义值时定义预处理器值

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:13 25 4
gpt4 key购买 nike

有时我看到一个define 预处理器但没有赋值给它。例如:

#define VAR

当没有指定值时,分配给 VAR 的是什么?

我也在阅读一篇文章,我看到了:

#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H

/* Error diagnostic routines */

void errMsg(const char *format, ...);

#ifdef __GNUC__

/* This macro stops 'gcc -Wall' complaining that "control reaches
end of non-void function" if we use the following functions to
terminate main() or some other non-void function. */

#define NORETURN __attribute__ ((__noreturn__))
#else
#define NORETURN
#endif

ERROR_FUNCTIONS_H 是头文件吗?或者这只是一个由 define 预处理器定义的常量?

最佳答案

它只是“已定义”,因此您可以像 #ifdef ERROR_FUNCTIONS_H 一样进行检查

如果你有

 #define ERROR_FUNCTIONS_H

你可以稍后做:

#ifdef ERROR_FUNCTIONS_H
//do something
#endif

#ifdef 中的代码将被编译。

ERROR_FUNCTIONS_H 不是头文件。它只是供预处理器使用的 #define

你的例子中有什么:

#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H

通常放在 .h 文件的顶部,以确保它只包含一次,这样您就不会得到多个定义。

关于c - 未定义值时定义预处理器值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22671006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com