相关疑难解决方法(0)

为什么GCC在编译时不评估constexpr?

举个例子:

class something {
public:
  static constexpr int seconds(int hour, int min, int sec)
  { return hour*3600+min*60+sec; }
}
Run Code Online (Sandbox Code Playgroud)

然后:

printf("Look at the time: %d\n", something::seconds(10, 0, 0));
Run Code Online (Sandbox Code Playgroud)

将编译为使用g ++调用函数,而不是使用常数.为什么g ++会这样做?它没有任何好处,有点挫败了使用constexpr而不是糟糕的宏的目的.

c++ gcc constexpr c++11

5
推荐指数
1
解决办法
1139
查看次数

标签 统计

c++ ×1

c++11 ×1

constexpr ×1

gcc ×1