2

所以我曾经认为使用-std=c11并且-pedantic-errors足以强制gcc只编译也可以在其他符合标准的编译器上编译的代码(可能在其他平台上,假设没有使用特定于平台的库),例如其他版本的 gcc 或其他编译器完全。

然而,显然在 Windows 7 上的 mingw 下编译两者都-pedantic-errors -std=c11允许编译包含以下内容的代码:

struct foo {
    //(some members)
};
struct bar {
    struct foo; //note the lack of a member name
    //(other members)
};

这导致相同的代码,也使用 gcc 两者-pedantic-errors -std=c11都在 Ubuntu 下失败error: declaration does not declare anything

如果 ISO-C11 中不允许匿名成员 like,那么为什么 gcc 首先让该代码通过?我-pedantic-errors -std=c11实际上错过了什么?我还需要哪些其他参数(如果有)来确保 gcc 仅编译足以在其他版本的 gcc、其他平台和/或其他编译器上工作的代码,因为这些编译器本身是符合标准的?即使其跨平台一致。

我不是在问目的-pedantic-errors是什么,而是什么参数可以强制 gcc 只编译可以在任何地方编译的代码(即没有特定于 gcc 的扩展或并不总是有效的非标准东西)。因此-pedantic-errors,更严格的是,由于-pedantic-errors仍然允许扩展,它只禁止标准中明确禁止的扩展。

4

0 回答 0