-3

Isn't the c89 standard supposed to be consistent ?

I'm compiling with gcc -W -Wall -std=c89 -pedantic -O3

On macOS, gcc is an alias of clang it seems : gcc --version returns Apple clang version 14.0.0 (clang-1400.0.29.201). It gives no warnings about powf, and the program behaves as expected.

Whereas on linux it's the real deal. It gives all the errors / warnings expected and doesn't compile.

ice-wind
  • 690
  • 4
  • 20
  • What compiler are you using that accepts the `-c89` option? Does it have a version number? Can you also show a [mre] so that we can exclude you not including the proper header as the reason? – Ted Lyngmo Oct 28 '22 at 18:32
  • @Ted Lyngmo Well I thought I was using `gcc` but under closer inspection it's secretly `clang` on macOS... – ice-wind Oct 28 '22 at 18:35
  • Ok, so have you done `#include `? Please add a small program demonstrating the problem. – Ted Lyngmo Oct 28 '22 at 18:36
  • Btw, normal `clang` doesn't accept `-c89` so that must be a Mac extension. `gcc` on linux doesn't accept it either. – Ted Lyngmo Oct 28 '22 at 18:36
  • @TedLyngmo Yes, on Mac it conflicts but not on linux. I have completely reworded the question now that I know gcc is secretly clang. – ice-wind Oct 28 '22 at 18:38
  • I am very curious to know who you need to support C89. – Cheatah Oct 28 '22 at 18:39
  • `-c89` is not a valid `clang` nor `gcc` option, it would be `-std=c89`. Can you show exactly how you're running these compilers? – Schwern Oct 28 '22 at 18:41
  • @Cheatah Projects with really cumbersome rules for how/when upgrades are ok. Nuclear plants, autonomous railway trains ... etc.. :-) – Ted Lyngmo Oct 28 '22 at 18:41
  • @Schwern I'm compiling with the `gcc` command on Mac, which says it is `Apple clang` when you type `gcc --version` – ice-wind Oct 28 '22 at 18:42
  • 3
    Please show a code example - it needs to be 5 lines tops + the command line you use to compile it. – Ted Lyngmo Oct 28 '22 at 18:43
  • 2
    Ok, voting to close the question. We don't have the [mre] we need to tell you what you are doing wrong. – Ted Lyngmo Oct 28 '22 at 18:45
  • 1
    Please provide a code example, how you're running the compilers (particularly any warning flags), and the different warnings you're receiving. – Schwern Oct 28 '22 at 18:47

1 Answers1

1

I'm compiling with -c89, and on Linux I have to define powf myself but on macOS it's already defined. Why is there a difference ?

The specifications for the standard library of C89 include a pow() function with arguments of type double that returns a double, but none for a powf() function. C99 added powf() as an analog that accepts arguments of type float and returns a float.

How different compilers for different machines handle that when asked to compile in a mode that requests conformance with a specific version of the language specification is specific to those compilers. That's all that really can be said about why you observe a difference.

But do note that the difference you observe might not be the difference you think you observe. If compiling in C89 mode means that no declaration of powf() is provided by math.h then that does not imply that C89 programs that call that function will not compile. On the contrary, such programs should still compile, but their calls to powf() will produce undefined behavior, probably incorrect behavior, as a result of the powf() function that is in fact present in the system libraries not having the signature that a C89 processor should infer from a call to that function when no prototype is in scope.

Isn't the c89 standard supposed to be consistent ?

The C89 standard is a singular document. It cannot fail to be consistent. But how different compilers implement c89 conformance modes is not consistent.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • I have all the warning flags as well, and no warning is produced, and the program behaves normally, so I think clang just includes the powf for some reason ? – ice-wind Oct 28 '22 at 18:49
  • That seems plausible, @Crysambrosia. It may well be that Clang's C89 conformance mode affects only its interpretation of the syntax and semantics of the language, not the contents of the standard library. Then again, most aspects of what diagnostics are produced under what circumstances are at the discretion of the compiler. – John Bollinger Oct 28 '22 at 18:52
  • @Crysambrosia Are you sure you are even running the compiler in C89 mode? `-c89` is not an option recognized by any `clang` or `gcc` version I know so I don't know what impact it has on your compilers. – Ted Lyngmo Oct 28 '22 at 19:06