gpt4 book ai didi

c - 哪些#define 标识符保留给预处理器?

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

我想我曾经读到过 #define 值中的前导下划线,例如;

#define _FOO

被 ANSI C 或其他一些标准劝阻或禁止。今天我已经梳理了互联网,审查了 K&R 和 CRM,但找不到任何支持它的东西。我发现的最接近的是一个建议(没有合适的引用)预定义标识符总是以双下划线开头 结束,这样上面的内容就不会冲突。我问是因为我正在使用一个提示的新静态检查器:

#ifndef __FOO_H
#define __FOO_H
...
#endif // __FOO_H

#define 行,我找不到权威的答案,无论我是对的还是检查员是对的。

最佳答案

今天我梳理了 Internet,查看了 K&R 和 CRM,但找不到任何支持它的东西。

(C99, 7.1.3.p1) "All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use."

现在关于 K&R 书第 2 版,它是这样写的:

(K&R 2nd edition, 2.1) "Don't begin variable names with underscore, however, since library routines often use such names."

如果 CRM 实际上指的是 CARM(Harbison & Steele 的 C A 引用手册):

(CARM 5th edition, 10.1.1 Reserved Library Identifiers): "The identifiers that are reserved for C implementations to use include: [...] for macros, keywords, or global variables, identifiers beginning with _ and and either a second _ or an uppercase letter (except _ _ STDC_...)"

关于c - 哪些#define 标识符保留给预处理器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027252/

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