3

If I specify the standard to ANSI C with -std=c89, my code won't run until I perform certain changes to make it compliant with the standard. So do I even need -pedantic at this point if I've already set the -std=c89 flag?


By the way, the idea was to write C code which is as platform independet as possible. I was already using -pedantic as I knew it would make the compiler more strict. However, it also made sense to explicitly choose the ANSI C standard. For some reason I thought this would make -pedantic superfluous because the switch to ANSI C produced many errors in itself and appeared "strict enough".

finefoot
  • 9,914
  • 7
  • 59
  • 102
  • The question is unclear. Need it for what? Do you need `-pedantic` if the goal is just to get your code to compile? No. Do you need `-pedantic` if your goal is to help catch more errors? Yes. – Eric Postpischil Oct 19 '19 at 21:43

1 Answers1

1

No, even though both -pedantic and -std=c89 might individually cause your code to fail to compile, they don't do the same thing:

  • -std=c89 will tell the compiler which ISO standard to use (in this case ANSI C also known as C89 or C90)
  • -pedantic will tell the compiler how strict the chosen standard should be enforced

You can also find the following helpful hint in the man page. -std=c89 is equivalent to -ansi for which man gcc says:

The -ansi option does not cause non-ISO programs to be rejected gratuitously. For that, -pedantic is required in addition to -ansi.

finefoot
  • 9,914
  • 7
  • 59
  • 102
  • 1
    You might further mention that the purpose of `-ansi` or `-std=c*` is to ensure that conforming programs **do compile correctly** (e.g. no nonstandard keywords that might clash with valid identifier use by the application) and don't have behavior that deviates from what the standard specifies (e.g. no "GNU inline" alternate meaning for the `inline` keyword, or no sloppy handling of excess floating point precision) in the default profile. They don't gratuitously prevent non-conforming program source from being accepted (while `-pedantic-errors` would prevent that). – R.. GitHub STOP HELPING ICE Oct 19 '19 at 22:57
  • 1
    @R..: I think you mean non-*strictly*-conforming. To be sure, the definition of "conforming C program" is essentially meaningless, but the authors of the Standard have explicitly said they did not wish to demean useful programs that didn't happen to be portable. – supercat Oct 22 '19 at 19:41