Is an ANSI C-compliant implementation allowed to include additional types and functions in its standard library, beyond those enumerated by the standard? (An ideal answer would reference the relevant part of the ANSI standard.)
I ask particularly because Mac OS 10.7 declares the getline
function in stdio.h, even when compiling with gcc or clang using the -ansi
flag. This breaks several older programs that define their own getline
function. Is this a fault of Mac OS 10.7? (The man page for getline
on Mac OS 10.7 says that getline
conforms to the POSIX.1 standard, which came in 2008.)
Edit: To clarify, I find it odd that including stdio.h in an ANSI C89 program on Mac OS 10.7 also pulls in the declaration for the getline
function, since getline
is not one of the functions enumerated in the K&R (and presumably ANSI) description of stdio.h. In particular, attempting to compile noweb:
gcc -ansi -pedantic -c -o notangle.o notangle.c
In file included from notangle.nw:28:
getline.h:4: error: conflicting types for ‘getline’
/usr/include/stdio.h:449: error: previous declaration of ‘getline’ was here
Is it a bug in Mac OS 10.7 includes the declaration of getline
in stdio.h even when compiling for the ANSI C89 standard?
_POSIX_C_SOURCE 1
. (This value is supposed to enable only the ANSI C89/ISO C90 features.) These feature test macros are not documented in the Mac man page forgetline
, and thefeature_test_macros
man page doesn't exist on the Mac. I wouldn't have found them without your answer. Although your answer now doesn't answer my original question (is an ANSI C implementation allowed to declare other functions in its standard library), your answer addresses my actual problem. I would upvote twice if I could! – Coreen