Should I use “-ansi” or explicit “-std=…” as compiler flags?

后端 未结 2 998
醉酒成梦
醉酒成梦 2021-02-20 00:23

I\'ve read that ANSI C is not exactly the same as ISO C and compilers may differ in interpretation of what \"-ansi\" is about. (gcc maps it to C90, clang maps it to C89) At the

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 00:57

    -ansi and -std= compiler flags may be shared by other compilers but they are gcc flags.

    As of now -ansi is equivalent to -std=c89 in gcc but this may1) change in the future so I suggest you to use -std=c89 over -ansi. Indeed ISO c99 for example has also been ratified by ANSI.

    You should note that c89 and c90 are essentially the same C Standard. c89 is the ANSI name while c90 is the ISO name.

    From gcc page:

    There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. This standard, in both its forms, is commonly known as C89, or occasionally as C90, from the dates of ratification.


    1) As noted by Keith Thompson in the comments, even though it's probably unlikely as it would break many build scripts.

提交回复
热议问题