gpt4 book ai didi

c - 在 C 中使用 __cplusplus 未定义行为吗?

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

标准要求现代 C++ 编译器 #define__cplusplus

这通常用于 C 和 C++ 都可以使用的文件中,但实现方式略有不同。

但在 C(和 C++)中,在标识符中使用任何双下划线的行为是未定义的!

因此,如果 C 编译器看到类似的东西

#ifdef __cplusplus

那么行为是否未定义?

最佳答案

But in C (and C++ for that matter), the behaviour on using any double underscore in an identifier is undefined!

你把事情搞混了。使用一个不是未定义的行为,只是名称是保留的。关键是您不能自己定义一些,但是使用它们没问题。

来自 ISO 9899:2011:

7.1.3 Reserved identifiers

— All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.

关于c - 在 C 中使用 __cplusplus 未定义行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44924777/

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