HDFGroup / HDFGroup/hdf5

feholdexcept causes HDF5 initialization to fail

Open
#6,493 0 comments 2 reactions 1 assignee Claimed by @lrknox View on GitHub
Dominant language
C
Stars
988
Forks
355
Avg merge
4d 2h
Merged PRs (30d)
12

Description

**Describe the bug**
I work on a multi-language product that mixes C++ and Fortran. We use NetCDF-Fortran, which in turn uses NetCDF and therefore HDF5. In Debug we compile our Fortran code with the /fpe:0 flag, which disables trapping for floating point exceptions. This causes the runtime initialization of HDF5 to fail, which we traced back to this call to feholdexcept: https://github.com/HDFGroup/hdf5/blob/2b0fd612f2e7db858a3cb3188d94544dcd209d3e/src/H5Tinit_float.c#L476

It seems like MSVC runtime's feholdexcept returns non-zero when this fpe:0 flag is enabled, which in turn triggers triggers the `can't save floating-point environment` error during initialization. It's likely to be related to this change: https://github.com/HDFGroup/hdf5/pull/3837/changes

I don't want to burden any of you with our complex build environment so I added a minimal example that reproduces the issue using equivalent C flags. Note that this no longer has anything to do with Fortran of the /fpe:0 flag, it is strictly trying to reproduce feholdexcept returning non-zero. Full disclosure: this example was generated using an LLM.

[Minimal_example.zip](https://github.com/user-attachments/files/29455940/Minimal_example.zip)

**Expected behavior**
HDF5 should make it through the initialization phase without issues, even with with /fpe:0.

**Platform (please complete the following information)**
- HDF5 version: 1.14.6 (but I believe it was caused in 1.14.4)
- OS and version: Windows 11 Enterprise 25H2
- Compiler and version: MSVC 19.44.35222, Intel IFX 2024.2.1 (Fortran, not relevant for miminal example)
- Build system (e.g. CMake version) and generator (e.g. XCode, Ninja): CMake 3.31.12, VS 2022 17.14.25
- Any configure options you specified
- MPI library and version (parallel HDF5)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.