Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function overload resolution with hsize_t fails in hdf5 >= 1.13.0 #11

Open
jngrad opened this issue Aug 5, 2023 · 0 comments
Open

Function overload resolution with hsize_t fails in hdf5 >= 1.13.0 #11

jngrad opened this issue Aug 5, 2023 · 0 comments

Comments

@jngrad
Copy link

jngrad commented Aug 5, 2023

The source code currently contains function overloads that match against two size types, std::size_t and hsize_t, e.g.:

/** construct simple dataspace of given extents, boost::array version */
template <std::size_t N>
dataspace(boost::array<std::size_t, N> const& dims);
template <std::size_t N>
dataspace(boost::array<hsize_t, N> const& dims);

This design decision was probably motivated by the guessing mechanism for integer type sizes in hdf5 versions < 1.13.0, where hsize_t was defined as:

typedef unsigned long long hsize_t;

(sources: v1.10.0 and v1.12.0). In function overload resolution, this type is considered different from std::size_t (typically defined as unsigned long on 64-bit architectures), although they have the same size.

Starting with hdf5 1.13.0 (HDFGroup/hdf5#709), it is now defined as:

typedef uint64_t hsize_t;

(sources: v1.13.0 and v1.14.1), which can be identical to std::size_t on 64-bit implementations, in which case overload resolution would fail.

One could solve this compatibility issue by wrapping all std::size_t overloads inside adequate ifdef guards, for example:

#include <H5public.h>
#if H5_VERSION_GE(1,13,0)
#define H5XX_PROVIDE_SIZE_T_OVERLOADS
#endif

/* ... */

#ifdef H5XX_PROVIDE_SIZE_T_OVERLOADS
 template <std::size_t N> 
 dataspace(boost::array<std::size_t, N> const& dims);
#endif
 template <std::size_t N> 
 dataspace(boost::array<hsize_t, N> const& dims);

The correct solution will likely look a bit more complicated than that, once portability concerns are factored in. For example, on 32-bit architectures std::size_t can be 4 bytes wide, in which case it is not equivalent to uint64_t and the std::size_t overloads are still needed.

Many thanks to William Brown for initially reporting the issue on the ESPResSo mailing list (thread from Fri, 4 Aug 2023, link).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant