`__assert` 是从哪里来的?

14

在阅读glibc源代码时,我偶然发现了assert.h中的这个注释:

/* The following is not at all used here but needed for standard
   compliance.  */
extern void __assert (const char *__assertion, const char *__file, int __line)
     __THROW __attribute__ ((__noreturn__));

哪个标准规定了__assert函数?

我在POSIX或C标准、git提交历史记录、网络或本站上都找不到相关信息。


我偶然发现了这个链接(https://www.rowleydownload.co.uk/avr/documentation/index.htm?https://www.rowleydownload.co.uk/avr/documentation/__assert.htm),但请注意在C89中没有`__func__`,所以[assert](http://jfxpt.com/library/c89-draft.html#4.2)宏“会写入关于失败调用的特定信息(包括参数的文本、源文件的名称和源代码行号)”。`__assert_fail`和`__assert_perror_fail`都有`const char *__function`参数,而这个没有。 - undefined
看起来这是由Ulrich Drepper于2000年添加的 - undefined
1
这里可能缺少一些背景信息。标准要求使用assert()函数,而不是__assert()函数。也许在某个地方有一个宏或编译器的魔法,将assert()转换成了__assert()。 - undefined
3
所有包含__(双下划线)的标识符都被保留供实现使用。因此,glibc(GNU C实现的一部分)可以自由地使用像__assert这样的名称来表示其内部任何内容,而不会与符合标准的程序或库的任何用途发生冲突。 - undefined
1个回答

2
我在浏览邮件列表时找到了这个信息:glibc应该符合Sys V ABI标准,因此应该实现__assert()函数
引用: ABI标准虽然不如源代码标准重要,但仍然是标准。 System V ABI(可从ftp://ftp.linux.sgi.com/pub/linux/mips/doc/ABI和其他地方获取)规定了一个名为__assert的函数。 我认为gcc(在libgcc中)和glibc(在libc.a中)都应该实现__assert。 如果它在标准中的存在不足以成为一个好理由,那么这里有一个实际的bug:这是为了让glibc能够替换Solaris上的libc所必需的。当然,glibcers会认为这是一个崇高的目标。 引用:“移植库并不难。”把这看作是Solaris移植的开始。 当然,glibc还需要实现Solaris libc中的其他符号,以实现与Solaris的二进制兼容性。如果它们在glibc中还不存在,大部分可能可以从libgcc中复制过来。
System V ABI Edition 4.1第6-9页中:

图6-6libc 内容,无同义词的内部名称

_cleanup _xftw __flsbuf __trwctype* _tolower __assert __iswctype* ___errno* _toupper __filbuf __thr_errno*


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接