为什么包括< regex>原因SQRT(负数)抛出域异常

发布于 2025-01-24 23:20:50 字数 487 浏览 2 评论 0原文

我有一个程序,该程序定期接受负数的std :: sqrt(),并根据需要检查NAN。

使用GCC 6.3.0(在嵌入式平台上),如果我

#include <regex> 

在同一库中,而不是返回NAN,则会引发异常。

当使用GCC 8.1(在Windows)和Clang(在Mac中)构建时,相同的代码

在调用所有其他标题之前尝试明确设置

#define math_errhandling MATH_ERRNO 

,并且似乎没有效果。

更新:

我将其跟踪到__errno()是这里的实际问题。我发现在第三方库中有一份声明:

int __errno = 0;

如果称为功能,这显然会导致SEG错误。

目前尚不清楚为什么包括Regex将其链接到此库,但删除此问题可以解决问题。

I have a program that regularly takes the std::sqrt() of negative numbers and checks for NaN as required.

Using gcc 6.3.0 (on an embedded platform), if I

#include <regex> 

in the same library, instead of returning NaN it will throw an exception.

The same code runs correctly when built using GCC 8.1 (in Windows) and Clang (in Mac)

I tried explicitly setting

#define math_errhandling MATH_ERRNO 

before calling all my other headers and it doesn't seem to have an effect.

Update:

I tracked this down to __errno() being the actual problem here. I found that in a 3rd party library there was a declaration:

int __errno = 0;

Which will clearly cause a seg fault if called as a function.

It’s still not clear why including regex caused it to link to this library, but removing this fixes the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文