gpt4 book ai didi

c++ - 在 constexpr 中使用 strcmp 的编译器差异

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

以下在 GCC 中编译但不在 Clang 中编译:

#include <cstring>

constexpr int test = strcmp("test", "test");

所以我的问题是,GCC 如何以不同方式处理 strcmp 以使其成为可能? strcmp 是某种类型的内置函数,还是它的标准库具有包含 constexpr 的 strcmp 的非标准定义?

最佳答案

代码在 gcc 上编译,因为它提供了一个 built-in version在编译时评估的 strcmp ,假设您将字符串文字传递给函数。

gcc 将 reject the code如果您传递 -fno-builtin(或 -fno-builtin-strcmp)标志。

关于c++ - 在 constexpr 中使用 strcmp 的编译器差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520781/

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