Date: Tue, 15 Jun 2021 22:54:14 -0400 From: Kurt Hackenberg <kh@panix.com> To: freebsd-questions@freebsd.org Subject: Re: Why doesn't cc -ansi disable conflicting type for getline from stdio.h? Message-ID: <4018acc9-2607-67ed-0327-8a3c9bc647b8@panix.com> In-Reply-To: <DM6PR03MB3674F7BEABFB85367768AE1BE6319@DM6PR03MB3674.namprd03.prod.outlook.com> References: <DM6PR03MB3674F7BEABFB85367768AE1BE6319@DM6PR03MB3674.namprd03.prod.outlook.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 > -std=c89? 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 include getline(). 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.) <https://en.wikipedia.org/wiki/POSIX> <https://en.wikipedia.org/wiki/C_POSIX_library> 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[1], 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. [1] C and Unix are 50 years old! That's pretty damn old for software.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4018acc9-2607-67ed-0327-8a3c9bc647b8>