gpt4 book ai didi

c++ - 在 GCC/G++ 编译器中使用 -pedantic 的目的是什么?

转载 作者:IT老高 更新时间:2023-10-28 11:33:43 27 4
gpt4 key购买 nike

This note说:

-ansi: tells the compiler to implement the ANSI language option. This turnsoff certain "features" of GCC whichare incompatible with the ANSIstandard.

-pedantic: used in conjunction with -ansi, this tells the compiler to be adhere strictly to the ANSI standard,rejecting any code which is notcompliant.

第一件事:

  • GCC/G++编译器的-pedantic-ansi选项有什么作用(上面的描述看不懂)?
  • 使用这两个选项的正确情况是什么?
  • 我应该什么时候使用它们?
  • 它们重要吗?

最佳答案

我在编码中一直使用它。

-ansi 标志等同于 -std=c89。如前所述,它关闭了 GCC 的一些扩展。添加 -pedantic 会关闭更多扩展并生成更多警告。例如,如果您的字符串文字长度超过 509 个字符,则 -pedantic 会发出警告,因为它超出了 C89 标准要求的最小限制。也就是说,每个 C89 编译器都必须接受长度为 509 的字符串;它们被允许接受更长的时间,但是如果你是迂腐的,那么使用更长的字符串是不可移植的,即使编译器被允许接受更长的字符串,并且在没有迂腐警告的情况下,GCC 也会接受它们。

关于c++ - 在 GCC/G++ 编译器中使用 -pedantic 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2855121/

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