小编DMa*_*ter的帖子

为什么空数组的大小为0但空类的大小不为0?

例如:

int main() {
  struct {} foo;
  int bar[0];
  struct {
    int dummy[0];
  } baz;
  cout << sizeof(foo) << endl; //display '1'
  cout << sizeof(bar) << endl; //display '0'
  cout << sizeof(baz) << endl; //display '0'
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

请告诉我是否有任何理由支持编译器行为

c++ gcc g++

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

__cplusplus <201402L即使我指定-std = c ++ 14,也会在gcc中返回true

指令:

#ifndef __cplusplus
  #error C++ is required
#elif __cplusplus < 201402L
  #error C++14 is required
#endif
Run Code Online (Sandbox Code Playgroud)

命令行: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp

我的g ++版本: g++ (tdm-1) 4.9.2

C++14 is required即使我添加了错误也会生成-std=c++14,我不知道为什么.

请告诉我如何解决这个问题.

c++ gcc g++ predefined-macro c++14

2
推荐指数
1
解决办法
5249
查看次数

标签 统计

c++ ×2

g++ ×2

gcc ×2

c++14 ×1

predefined-macro ×1