样板 CRT 函数 matherr 有什么意义?

What is the point of the boilerplate CRT function matherr?

我用 C:

写了一个基本的 "Hello World" 程序
#include <stdio.h>

int main()
{
        printf("Hello World!\n");
        return 0;
}

然后,我从命令行在 MSVC 中编译它:

cl hello.c /Fd:hello.pdb /Zi /MD /link /NODEFAULTLIB:LIBCMT.LIB

命令行参数基本上说 "generate a PDB file and link with MSVCRT.LIB rather than LIBCMT.LIB"。

然后,我反汇编了程序,查看了各种boilerplate/CRT函数,在反汇编中发现了这个,很好奇:

__matherr:
  00401550: 33 C0              xor         eax,eax
  00401552: C3                 ret

这基本上是一个函数,无论何时被调用,它在 EAX 中总是 returns 0。根据这个函数的the documentation,当出现数学错误时returns 0,当没有错误时它是非0。

有没有人知道为什么这个在数学错误的情况下应该是 return 0 的函数包含在可执行文件中并被硬编码为 总是 return 0?

如果检测到数学异常,

matherr 应该从各种数学函数中调用。默认实现什么都不做。在某些平台上,可以有选择地将 C 库函数替换为用户定义的代码("function interposition" 在 ELF 系统上),因此您可以实现自己的数学错误处理程序。据我所知,Windows 上的可移植可执行文件 (PE) 无法做到这一点。我想 matherr 是 CRT 的一部分只是出于兼容性原因。