News for hackers. Stuff that matters.
Re:Forward Referencing in C by jepler on Sunday June 04, 2023 @08:35PM (#36190934)
I wish folks would be wary of saying "such and such is legal in C _because an implementation accepts it_".

I'm well aware that the practice is for compilers to accept this; it was a standard "feature" of K&R C. However, per Wikipedia, this feature was removed in C99 <https://en.wikipedia.org/wiki/ANSI_C#C99> a fact that I verified in the forward to the C99 draft standard ISO/IEC 9899:TC3. So I'm a little surprised that the construct is only treated with a warning in `gcc -std=c99 -ansi -pedantic -Wall`.

Re:Forward Referencing in C by xorvoid on Monday June 05, 2023 @12:51AM (#36192419)
There must be other context to the tweet because I’m sure that Walter Bright knows all of that..
Re:Forward Referencing in C by n4r9 on Monday June 05, 2023 @06:46AM (#36194626)
To be fair, the linked Tweet does not claim it is legal behaviour. Just that it ought to be possible, in principle, in at least some situations.
Re:Forward Referencing in C by classified on Monday June 05, 2023 @09:15AM (#36195742)
Just declare fwd() with a prototype, and everything's good.
Re:Forward Referencing in C by pjmlp on Monday June 05, 2023 @02:18AM (#36193023)
First they need to learn to distinguish what is ISO C and whateve their compiler accepts, the large majority doesn't.

Hence why so many just try to use GCC everywhere (nowadays clang as well).

Re:Forward Referencing in C by eqvinox on Monday June 05, 2023 @03:30AM (#36193517)
> So I'm a little surprised that the construct is only treated with a warning

GCC does that for everything short of actual things it can't compile, you have to use -Werror[=…] to make it error out.

Re:Forward Referencing in C by parasti on Monday June 05, 2023 @06:57AM (#36194699)
-ansi translates to -std=c90, so you're effectively cancelling the -std=c99.
Re:Forward Referencing in C by gpderetta on Monday June 05, 2023 @07:33AM (#36194907)
Recently GCC moved to make this an hard error by default in >=C99 mode. There was huge push back form some very vocal members of the community against such exoteric, bleeding edge type system non-sense like function prototypes; according to them having to add -pedantic gcc command-line to build legacy code is an unreasonable breaking change. The burden should be on beginners to find the correct GCC arguments to enable all the "useless" warning.

Thankfully GCC is going ahead with the change anyway.

Re:Forward Referencing in C by unwind on Monday June 05, 2023 @08:30AM (#36195303)
Yeah, perhaps even more when they wrote said implementation. :) Nothing against WalterBright, I just thought it was funny to use your own compiler as a referene like that.

I don't quite understand the point, is forward references to undeclared things something to strive after?

Re:Forward Referencing in C by MathMonkeyMan on Monday June 05, 2023 @08:53AM (#36195521)
It prevents you from having to topologically sort your definitions, or otherwise declare everything at the top. Since idiomatic C uses header files, though, it doesn't matter too much. Main benefit is that non-public implementation details (e.g. static functions) needn't be declared at the top of the source file.
Re:Forward Referencing in C by taneq on Monday June 05, 2023 @08:38AM (#36195370)
There’s no such language as C anyway, strictly speaking. There’s the C standard which defines a family of languages, then there’s the (C compiler version, OS, misc factors) tuples that define actual C-like languages.
Re:Forward Referencing in C by kyberias on Monday June 05, 2023 @08:52AM (#36195515)
What is ANSI C or C99 then?
Re:Forward Referencing in C by MathMonkeyMan on Monday June 05, 2023 @08:56AM (#36195554)
According to the parent post, two families of languages. I disagree, though. Each standard _is_ a language. But which one does your compiler implement?
Re:Forward Referencing in C by taneq on Monday June 05, 2023 @12:10PM (#36198422)
Exactly, it's "a language" but what you say will be interpreted differently depending on which specific version of which specific compiler you happen to be using today.
Re:Forward Referencing in C by jmclnx on Monday June 05, 2023 @10:22AM (#36196556)
I not think you know who Walter Bright is :)

In my opinion he wrote wrote of the best c/c++ compilers for DOS. If he says something compiler (c) related, I usually pay attention.