且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++编译时常数检测

更新时间:2021-08-29 17:41:29

GCC,使用 __ builtin_constant_p 告诉你某个东西是否是编译时常量。该文档包括例如

If you're working with GCC, use __builtin_constant_p to tell you whether something is a compile time constant. The documentation includes examples like

static const int table[] = {
  __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
  /* ... */
};