gpt4 book ai didi

c++ - __COUNTER__ 宏是否可移植?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:21 25 4
gpt4 key购买 nike

我有一段代码使用 __COUNTER__ 宏来为变量生成唯一的名称。

此代码可移植吗?我知道 GCC 和 MSVS 支持它。其他编译器呢?宏是由标准定义的吗(据我所知,在 C++14 之前它不是)。

最佳答案

这绝对标准。

这是一个编译器扩展(GNU C extensions)

The common predefined macros are GNU C extensions.

和一个Microsoft-specific one ,

Microsoft-Specific Predefined Macros:

__ COUNTER __

还支持clang作为语言扩展。

The standard doesn't mention it anywhere .

关于c++ - __COUNTER__ 宏是否可移植?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26160235/

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