Why doesn't cc -ansi disable conflicting type for getline from stdio.h?
kh at panix.com
Wed Jun 16 02:54:20 UTC 2021
On 2021/06/14 17:10, Edward Sanford Sutton, III wrote:
> Trying to work on properly learning C so following K&R second edition
> of C Programming Language. Found in manpage that -std=c89 or -ansi can
> be passed to setup a more compatible set of build rules which hid
> warnings about how main is defined.
> My understanding is that this should also cause getline to not be
> defined in /usr/include/stdio.h. Is there a reason that "#if
> __POSIX_VISIBLE >= 200809" should trigger as true in there with
Huh. I didn't know about that function getline() as part of the C
library. The latest C reference I have is for C99, 1999; it doesn't
You may have run across dueling standards or something. Posix defines a
standard Unix, and apparently also defines a C standard library that's a
little larger than the C standard library defined by the C standard,
even though Posix doesn't define C. (Yes, that's a little weird.)
The boundary between C and Unix has always been blurred a little in
practice. It's good to keep the boundary clear in your mind, but you
might have to accept some imperfection in software.
I suggest you take that getline() thing as a glitch, the kind of thing
that shows up in old software, and work around it without worrying
about it too much. Definitely rename the function in the sample program.
As for learning C, K & R is the classic for that, but it's 30 years old.
I suggest that you go through that, and when you more or less have a
handle on the language, also look at more modern versions of C. There
were significant changes in 1999 and 2011 -- not fundamental changes,
but some useful additions.
 C and Unix are 50 years old! That's pretty damn old for software.
More information about the freebsd-questions