【发布时间】:2011-11-14 15:34:54
【问题描述】:
是否允许符合 ANSI C 的实现在其标准库中包含超出标准枚举的其他类型和函数? (理想的答案是参考 ANSI 标准的相关部分。)
我之所以这么问,是因为 Mac OS 10.7 在 stdio.h 中声明了 getline 函数,即使在使用 gcc 或 clang 使用 -ansi 标志编译时也是如此。这破坏了几个定义自己的 getline 函数的旧程序。这是 Mac OS 10.7 的故障吗? (Mac OS 10.7 上 getline 的手册页显示 getline 符合 2008 年推出的 POSIX.1 标准。)
编辑:澄清一下,我觉得奇怪的是,在 Mac OS 10.7 上的 ANSI C89 程序中包含 stdio.h 也会引入 getline 函数的声明,因为 getline 不是枚举的函数之一stdio.h 的 K&R(可能是 ANSI)描述。特别是尝试编译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
这是 Mac OS 10.7 中的一个错误,即使在针对 ANSI C89 标准进行编译时,也会在 stdio.h 中包含 getline 的声明?
【问题讨论】:
标签: c standards ansi osx-lion getline