2013-08-22 181 views
1

从人3字符串错误:不同版本的功能与同名

int strerror_r(int errnum, char *buf, size_t buflen); 
     /* XSI-compliant */ 

char *strerror_r(int errnum, char *buf, size_t buflen); 
     /* GNU-specific */ 

...

This function is available in two versions: an XSI-compliant version specified in POSIX.1-2001 (available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13), and a GNU-specific version (available since glibc 2.0). The XSI-compliant version is provided with the feature test macros settings shown in the SYNOPSIS; otherwise the GNU-specific version is provided.

是否真的glibc的同时提供这些功能呢?如果是这样,链接器如何区分它们。当涉及到链接时,所有预处理器定义都消失了,所以这里发生了什么?

回答

2

看一看<string.h>。当使用XSI兼容的版本,它使用宏重新定义strerror_r

# define strerror_r __xpg_strerror_r 

有一个在连接器没有混乱,因为xpg_strerror_r是不同的功能。