# Issues with H5T\_NATIVE\_LDOUBLE

**URL:** <https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991>\
**Category:** Hdf-forum archives\
**Created:** [September 3, 2013, 5:30am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991 "2013-09-03T05:30:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 3, 2013, 5:30am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/1 "2013-09-03T05:30:30Z")

</div>

Hi,

I am experiencing the following issue with hdf5 and gcc 4.8.0

Consider this very simple test

#include \<hdf5.h\>

int main() {  
&nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
&nbsp;&nbsp;case H5T\_ORDER\_LE:  
&nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
&nbsp;&nbsp;&nbsp;&nbsp;break;  
&nbsp;&nbsp;case H5T\_ORDER\_BE:  
&nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
&nbsp;&nbsp;&nbsp;&nbsp;break;  
&nbsp;&nbsp;case H5T\_ORDER\_VAX:  
&nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
&nbsp;&nbsp;&nbsp;&nbsp;break;  
&nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
&nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
&nbsp;&nbsp;&nbsp;&nbsp;break;  
&nbsp;&nbsp;case H5T\_ORDER\_NONE:  
&nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
&nbsp;&nbsp;&nbsp;&nbsp;break;  
&nbsp;&nbsp;default:  
&nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
&nbsp;&nbsp;}  
&nbsp;&nbsp;return 0;  
}

on the same x86\_64 GNU/Linux machine I get

$ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE

$ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX

So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and basically  
the fault must be in src/H5detect.c which is used to generate the  
definitions in src/H5Tinit.c  
I could not figure out what H5detect.c does wrong (it is not very readable,  
given its extensive use of macros) but the compiler does emit a lot of  
warnings (see [https://gist.github.com/andreabedini/6419975](https://gist.github.com/andreabedini/6419975)).

I think this must be related to the failure of dt\_arith long double test  
observed recently.

Any suggestion on how to fix this ?

Best wishes,  
Andrea

> **···**
>
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 3, 2013, 8:32am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/2 "2013-09-03T08:32:15Z")

</div>

Hi there,

I think I have found the problem. The issue is in H5detect.c.  
Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
the detected\_t struct. As a result the routine fix\_order is passed some  
uninitialized memory which makes it fail. I have a small patch against  
H5detect.c which fixes the problem by simply initializing the perm field  
with zeros. Valgrind's tool memcheck would have exposed the problem.

Best wishes,  
Andrea

[hdf5\_uninitialized.patch](https://hdf-discourse-1.s3.amazonaws.com/original/1X/929eb70424aaf7a7c7eac432e6942f77045e597c.patch) (1.28 KB)

> **···**
>
> On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> 
> > Hi,
> > 
> > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > 
> > Consider this very simple test
> > 
> > #include \<hdf5.h\>
> > 
> > int main() {  
> > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > &nbsp;&nbsp;}  
> > &nbsp;&nbsp;return 0;  
> > }
> > 
> > on the same x86\_64 GNU/Linux machine I get
> > 
> > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > 
> > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > 
> > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and basically  
> > the fault must be in src/H5detect.c which is used to generate the  
> > definitions in src/H5Tinit.c  
> > I could not figure out what H5detect.c does wrong (it is not very  
> > readable, given its extensive use of macros) but the compiler does emit a  
> > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > 
> > I think this must be related to the failure of dt\_arith long double test  
> > observed recently.
> > 
> > Any suggestion on how to fix this ?
> > 
> > Best wishes,  
> > Andrea
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Raymond\_Lu](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@Raymond\_Lu](https://forum.hdfgroup.org/u/Raymond_Lu)\
**Post date:** [September 3, 2013, 7:43pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/3 "2013-09-03T19:43:43Z")

</div>

Andrea,

We've verified that your solution is correct. We're putting your fix into the library. Thanks for helping us.

Ray

> **···**
>
> On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> 
> > Hi there,
> > 
> > I think I have found the problem. The issue is in H5detect.c. Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in the detected\_t struct. As a result the routine fix\_order is passed some uninitialized memory which makes it fail. I have a small patch against H5detect.c which fixes the problem by simply initializing the perm field with zeros. Valgrind's tool memcheck would have exposed the problem.
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > Hi,
> > 
> > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > 
> > Consider this very simple test
> > 
> > #include \<hdf5.h\>
> > 
> > int main() {  
> > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > &nbsp;&nbsp;default:  
> > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > &nbsp;&nbsp;}  
> > &nbsp;&nbsp;return 0;  
> > }
> > 
> > on the same x86\_64 GNU/Linux machine I get
> > 
> > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > 
> > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > 
> > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and basically the fault must be in src/H5detect.c which is used to generate the definitions in src/H5Tinit.c  
> > I could not figure out what H5detect.c does wrong (it is not very readable, given its extensive use of macros) but the compiler does emit a lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > 
> > I think this must be related to the failure of dt\_arith long double test observed recently.
> > 
> > Any suggestion on how to fix this ?
> > 
> > Best wishes,  
> > Andrea
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > \<hdf5\_uninitialized.patch\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 3, 2013, 10:00pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/4 "2013-09-03T22:00:17Z")

</div>

Hi Ray,

thanks for giving it a look. Antonio made me notice that something else  
might be at work since the macro DETECT\_F already zeroes the structure  
right before anything else:

memset(&INFO, 0, sizeof(INFO)); #L299

so I don't understand how the perm fields need to be zeroed again around  
line #L308. This still considering the "Byte Order" loop as a black box.

As a side question: isn't there a more portable way of doing this? I am  
pretty sure H5detect.c might invoke a bunch of undefined behaviours given  
the amount of warning the compiler generates and of bit trickery.

Best wishes,  
Andrea

> **···**
>
> On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> 
> > Andrea,
> > 
> > We've verified that your solution is correct. We're putting your fix into  
> > the library. Thanks for helping us.
> > 
> > Ray
> > 
> > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > 
> > Hi there,
> > 
> > I think I have found the problem. The issue is in H5detect.c.  
> > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > the detected\_t struct. As a result the routine fix\_order is passed some  
> > uninitialized memory which makes it fail. I have a small patch against  
> > H5detect.c which fixes the problem by simply initializing the perm field  
> > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> > 
> > > Hi,
> > > 
> > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > 
> > > Consider this very simple test
> > > 
> > > #include \<hdf5.h\>
> > > 
> > > int main() {  
> > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;default:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > &nbsp;&nbsp;}  
> > > &nbsp;&nbsp;return 0;  
> > > }
> > > 
> > > on the same x86\_64 GNU/Linux machine I get
> > > 
> > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > 
> > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > 
> > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > definitions in src/H5Tinit.c  
> > > I could not figure out what H5detect.c does wrong (it is not very  
> > > readable, given its extensive use of macros) but the compiler does emit a  
> > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > 
> > > I think this must be related to the failure of dt\_arith long double test  
> > > observed recently.
> > > 
> > > Any suggestion on how to fix this ?
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > \<hdf5\_uninitialized.patch\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 4, 2013, 12:50am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/5 "2013-09-04T00:50:10Z")

</div>

Hi,

I found something else (I know, I should stop :)). I am not entirely sure  
but it seems that when H5detect fails it writes "unable to calculate  
alignment for long double" on stderr so this message should be observable  
on build logs (although buried by other warnings). The packages on debian  
sid and testing for both i386 and x86-64 seem to be affected:

[https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)  
[https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)

But here's the exciting part: look what I found

[http://www.unidata.ucar.edu/mailing\_lists/archives/gembud/2010/msg00052.html](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)

It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
to calculate alignment for long double".

If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
problem and it would be that piece of code just doesn't work properly.

Best wishes,  
Andrea

> **···**
>
> On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> 
> > Hi Ray,
> > 
> > thanks for giving it a look. Antonio made me notice that something else  
> > might be at work since the macro DETECT\_F already zeroes the structure  
> > right before anything else:
> > 
> > memset(&INFO, 0, sizeof(INFO)); #L299
> > 
> > so I don't understand how the perm fields need to be zeroed again around  
> > line #L308. This still considering the "Byte Order" loop as a black box.
> > 
> > As a side question: isn't there a more portable way of doing this? I am  
> > pretty sure H5detect.c might invoke a bunch of undefined behaviours given  
> > the amount of warning the compiler generates and of bit trickery.
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > 
> > > Andrea,
> > > 
> > > We've verified that your solution is correct. We're putting your fix  
> > > into the library. Thanks for helping us.
> > > 
> > > Ray
> > > 
> > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > 
> > > Hi there,
> > > 
> > > I think I have found the problem. The issue is in H5detect.c.  
> > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > uninitialized memory which makes it fail. I have a small patch against  
> > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > 
> > > > Consider this very simple test
> > > > 
> > > > #include \<hdf5.h\>
> > > > 
> > > > int main() {  
> > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;default:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > &nbsp;&nbsp;}  
> > > > &nbsp;&nbsp;return 0;  
> > > > }
> > > > 
> > > > on the same x86\_64 GNU/Linux machine I get
> > > > 
> > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > 
> > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > 
> > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > definitions in src/H5Tinit.c  
> > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > 
> > > > I think this must be related to the failure of dt\_arith long double test  
> > > > observed recently.
> > > > 
> > > > Any suggestion on how to fix this ?
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > \<hdf5\_uninitialized.patch\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![gnwiii](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/g/e5b9ba/32.png) [@gnwiii](https://forum.hdfgroup.org/u/gnwiii)\
**Post date:** [September 4, 2013, 12:58pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/6 "2013-09-04T12:58:08Z")

</div>

Another historical reference to the obscurity of this code is: \<  
[118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).

I've been building HDF5 libraries for use with NASA SeaDAS, and recently  
have started using HDF5 with R and GDAL. The SeaDAS builds are static, and  
I don't find the "unable to calculate alignment for long double" message in  
my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need  
dynamic libraries and those build logs do have the "unable to calculate  
alignment for long double" message on both linux and OS X.

> **···**
>
> On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> 
> > Hi,
> > 
> > I found something else (I know, I should stop :)). I am not entirely sure  
> > but it seems that when H5detect fails it writes "unable to calculate  
> > alignment for long double" on stderr so this message should be observable  
> > on build logs (although buried by other warnings). The packages on debian  
> > sid and testing for both i386 and x86-64 seem to be affected:
> > 
> > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > 
> > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > 
> > But here's the exciting part: look what I found
> > 
> > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > 
> > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > to calculate alignment for long double".
> > 
> > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > problem and it would be that piece of code just doesn't work properly.
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> > 
> > > Hi Ray,
> > > 
> > > thanks for giving it a look. Antonio made me notice that something else  
> > > might be at work since the macro DETECT\_F already zeroes the structure  
> > > right before anything else:
> > > 
> > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > 
> > > so I don't understand how the perm fields need to be zeroed again around  
> > > line #L308. This still considering the "Byte Order" loop as a black box.
> > > 
> > > As a side question: isn't there a more portable way of doing this? I am  
> > > pretty sure H5detect.c might invoke a bunch of undefined behaviours given  
> > > the amount of warning the compiler generates and of bit trickery.
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > 
> > > > Andrea,
> > > > 
> > > > We've verified that your solution is correct. We're putting your fix  
> > > > into the library. Thanks for helping us.
> > > > 
> > > > Ray
> > > > 
> > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > 
> > > > Hi there,
> > > > 
> > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > 
> > > > > Consider this very simple test
> > > > > 
> > > > > #include \<hdf5.h\>
> > > > > 
> > > > > int main() {  
> > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > &nbsp;&nbsp;default:  
> > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > &nbsp;&nbsp;}  
> > > > > &nbsp;&nbsp;return 0;  
> > > > > }
> > > > > 
> > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > 
> > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > 
> > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > 
> > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > definitions in src/H5Tinit.c  
> > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > > 
> > > > > I think this must be related to the failure of dt\_arith long double  
> > > > > test observed recently.
> > > > > 
> > > > > Any suggestion on how to fix this ?
> > > > > 
> > > > > Best wishes,  
> > > > > Andrea
> > > > > 
> > > > > --  
> > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > \<hdf5\_uninitialized.patch\>  
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> George N. White III \<aa056@chebucto.ns.ca\>  
> Head of St. Margarets Bay, Nova Scotia

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 5, 2013, 1:40am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/7 "2013-09-05T01:40:34Z")

</div>

Thanks George.

For anyone interested in debugging this problem, debian has an extensive  
collection of build logs over many architectures  
[Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)

As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE type.  
You can check your particular build with the following test

#include \<hdf5.h\>  
int main() {  
&nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(  
H5T\_NATIVE\_DOUBLE));  
}

It exits with code 1 if the long double has different byte ordering than  
double (which is technically possible, but highly suspicious).

Otherwise the patch I sent earlier in this thread seems to do the trick,  
although what exactly is going wrong is still beyond my understanding.

Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE yourself.  
The following creates a data type representing a long double as implemented  
by gcc on x86 architectures (see  
[long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)

hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
H5Tset\_size(ldouble\_datatype, sizeof(long double));  
H5Tset\_precision(ldouble\_datatype, 80);  
H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
H5Tset\_ebias(ldouble\_datatype, 16383);  
H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);

Best wishes,  
Andrea

> **···**
>
> On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:
> 
> > Another historical reference to the obscurity of this code is: \<  
> > [118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > 
> > I've been building HDF5 libraries for use with NASA SeaDAS, and recently  
> > have started using HDF5 with R and GDAL. The SeaDAS builds are static, and  
> > I don't find the "unable to calculate alignment for long double" message in  
> > my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need  
> > dynamic libraries and those build logs do have the "unable to calculate  
> > alignment for long double" message on both linux and OS X.
> > 
> > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > 
> > > Hi,
> > > 
> > > I found something else (I know, I should stop :)). I am not entirely sure  
> > > but it seems that when H5detect fails it writes "unable to calculate  
> > > alignment for long double" on stderr so this message should be observable  
> > > on build logs (although buried by other warnings). The packages on debian  
> > > sid and testing for both i386 and x86-64 seem to be affected:
> > > 
> > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > > 
> > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > 
> > > But here's the exciting part: look what I found
> > > 
> > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > 
> > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > > to calculate alignment for long double".
> > > 
> > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > > problem and it would be that piece of code just doesn't work properly.
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> > > 
> > > > Hi Ray,
> > > > 
> > > > thanks for giving it a look. Antonio made me notice that something else  
> > > > might be at work since the macro DETECT\_F already zeroes the structure  
> > > > right before anything else:
> > > > 
> > > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > > 
> > > > so I don't understand how the perm fields need to be zeroed again around  
> > > > line #L308. This still considering the "Byte Order" loop as a black box.
> > > > 
> > > > As a side question: isn't there a more portable way of doing this? I am  
> > > > pretty sure H5detect.c might invoke a bunch of undefined behaviours given  
> > > > the amount of warning the compiler generates and of bit trickery.
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > 
> > > > > Andrea,
> > > > > 
> > > > > We've verified that your solution is correct. We're putting your fix  
> > > > > into the library. Thanks for helping us.
> > > > > 
> > > > > Ray
> > > > > 
> > > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > > 
> > > > > Hi there,
> > > > > 
> > > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > > 
> > > > > Best wishes,  
> > > > > Andrea
> > > > > 
> > > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > > 
> > > > > > Consider this very simple test
> > > > > > 
> > > > > > #include \<hdf5.h\>
> > > > > > 
> > > > > > int main() {  
> > > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > &nbsp;&nbsp;default:  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > > &nbsp;&nbsp;}  
> > > > > > &nbsp;&nbsp;return 0;  
> > > > > > }
> > > > > > 
> > > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > > 
> > > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > > 
> > > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > > 
> > > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > > definitions in src/H5Tinit.c  
> > > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > > > 
> > > > > > I think this must be related to the failure of dt\_arith long double  
> > > > > > test observed recently.
> > > > > > 
> > > > > > Any suggestion on how to fix this ?
> > > > > > 
> > > > > > Best wishes,  
> > > > > > Andrea
> > > > > > 
> > > > > > --  
> > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > 
> > > > > --  
> > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > \<hdf5\_uninitialized.patch\>  
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > 
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > George N. White III \<aa056@chebucto.ns.ca\>  
> > Head of St. Margarets Bay, Nova Scotia
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Raymond\_Lu](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@Raymond\_Lu](https://forum.hdfgroup.org/u/Raymond_Lu)\
**Post date:** [September 5, 2013, 8:40pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/8 "2013-09-05T20:40:50Z")

</div>

I isolated part of the DETECT\_F into a C program as attached (detect.c). It only contains the algorithm for detecting the byte order of long double. When I compile it with gcc -g, -O0, or no flag, it reports little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX order. I don't know where goes wrong yet. But I suspect GCC's optimization has bugs. Maybe you can help me.

I haven't tried the algorithms for other parts in DETECT\_F yet. The alignment problem you talked about is one of the other algorithms.

Ray

[detect.c](https://hdf-discourse-1.s3.amazonaws.com/original/1X/b0652d15353afca1083907e1ba7b31f799acf7c8.c) (3.73 KB)

> **···**
>
> On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> 
> > Thanks George.
> > 
> > For anyone interested in debugging this problem, debian has an extensive collection of build logs over many architectures [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)
> > 
> > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE type. You can check your particular build with the following test
> > 
> > #include \<hdf5.h\>  
> > int main() {  
> > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(H5T\_NATIVE\_DOUBLE));  
> > }
> > 
> > It exits with code 1 if the long double has different byte ordering than double (which is technically possible, but highly suspicious).
> > 
> > Otherwise the patch I sent earlier in this thread seems to do the trick, although what exactly is going wrong is still beyond my understanding.
> > 
> > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE yourself. The following creates a data type representing a long double as implemented by gcc on x86 architectures (see [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > 
> > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > H5Tset\_precision(ldouble\_datatype, 80);  
> > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:  
> > Another historical reference to the obscurity of this code is: \<[118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > 
> > I've been building HDF5 libraries for use with NASA SeaDAS, and recently have started using HDF5 with R and GDAL. The SeaDAS builds are static, and I don't find the "unable to calculate alignment for long double" message in my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need dynamic libraries and those build logs do have the "unable to calculate alignment for long double" message on both linux and OS X.
> > 
> > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > Hi,
> > 
> > I found something else (I know, I should stop :)). I am not entirely sure but it seems that when H5detect fails it writes "unable to calculate alignment for long double" on stderr so this message should be observable on build logs (although buried by other warnings). The packages on debian sid and testing for both i386 and x86-64 seem to be affected:
> > 
> > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)  
> > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > 
> > But here's the exciting part: look what I found
> > 
> > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > 
> > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable to calculate alignment for long double".
> > 
> > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the problem and it would be that piece of code just doesn't work properly.
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > Hi Ray,
> > 
> > thanks for giving it a look. Antonio made me notice that something else might be at work since the macro DETECT\_F already zeroes the structure right before anything else:
> > 
> > memset(&INFO, 0, sizeof(INFO)); #L299
> > 
> > so I don't understand how the perm fields need to be zeroed again around line #L308. This still considering the "Byte Order" loop as a black box.
> > 
> > As a side question: isn't there a more portable way of doing this? I am pretty sure H5detect.c might invoke a bunch of undefined behaviours given the amount of warning the compiler generates and of bit trickery.
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:  
> > Andrea,
> > 
> > We've verified that your solution is correct. We're putting your fix into the library. Thanks for helping us.
> > 
> > Ray
> > 
> > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > 
> > > Hi there,
> > > 
> > > I think I have found the problem. The issue is in H5detect.c. Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in the detected\_t struct. As a result the routine fix\_order is passed some uninitialized memory which makes it fail. I have a small patch against H5detect.c which fixes the problem by simply initializing the perm field with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > > Hi,
> > > 
> > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > 
> > > Consider this very simple test
> > > 
> > > #include \<hdf5.h\>
> > > 
> > > int main() {  
> > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > &nbsp;&nbsp;default:  
> > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > &nbsp;&nbsp;}  
> > > &nbsp;&nbsp;return 0;  
> > > }
> > > 
> > > on the same x86\_64 GNU/Linux machine I get
> > > 
> > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > 
> > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > 
> > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and basically the fault must be in src/H5detect.c which is used to generate the definitions in src/H5Tinit.c  
> > > I could not figure out what H5detect.c does wrong (it is not very readable, given its extensive use of macros) but the compiler does emit a lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > 
> > > I think this must be related to the failure of dt\_arith long double test observed recently.
> > > 
> > > Any suggestion on how to fix this ?
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > \<hdf5\_uninitialized.patch\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org  
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > George N. White III \<aa056@chebucto.ns.ca\>  
> > Head of St. Margarets Bay, Nova Scotia
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 6, 2013, 6:49am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/9 "2013-09-06T06:49:10Z")

</div>

Hi Rey,

thanks for that, it really helped. I checked thoroughly and the memset of  
the temporary variables disappears randomly.  
It doesn't depends only on optimization though, on my machine putting a  
printf("%Lf\n", value2); just before the loop changes the result.  
I'm not sure who gets the blame here, poking into the padding bits of a  
long double might just be unspecified or undefined behaviour.

Andrea

> **···**
>
> On 6 September 2013 06:40, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> 
> > I isolated part of the DETECT\_F into a C program as attached (detect.c).  
> > It only contains the algorithm for detecting the byte order of long  
> > double. When I compile it with gcc -g, -O0, or no flag, it reports  
> > little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX  
> > order. I don't know where goes wrong yet. But I suspect GCC's  
> > optimization has bugs. Maybe you can help me.
> > 
> > I haven't tried the algorithms for other parts in DETECT\_F yet. The  
> > alignment problem you talked about is one of the other algorithms.
> > 
> > Ray
> > 
> > On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> > 
> > Thanks George.
> > 
> > For anyone interested in debugging this problem, debian has an extensive  
> > collection of build logs over many architectures  
> > [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)
> > 
> > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE  
> > type. You can check your particular build with the following test
> > 
> > #include \<hdf5.h\>  
> > int main() {  
> > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(  
> > H5T\_NATIVE\_DOUBLE));  
> > }
> > 
> > It exits with code 1 if the long double has different byte ordering than  
> > double (which is technically possible, but highly suspicious).
> > 
> > Otherwise the patch I sent earlier in this thread seems to do the trick,  
> > although what exactly is going wrong is still beyond my understanding.
> > 
> > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE yourself.  
> > The following creates a data type representing a long double as implemented  
> > by gcc on x86 architectures (see  
> > [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > 
> > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > H5Tset\_precision(ldouble\_datatype, 80);  
> > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > 
> > Best wishes,  
> > Andrea
> > 
> > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:
> > 
> > > Another historical reference to the obscurity of this code is: \<  
> > > [118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > > 
> > > I've been building HDF5 libraries for use with NASA SeaDAS, and recently  
> > > have started using HDF5 with R and GDAL. The SeaDAS builds are static, and  
> > > I don't find the "unable to calculate alignment for long double" message in  
> > > my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need  
> > > dynamic libraries and those build logs do have the "unable to calculate  
> > > alignment for long double" message on both linux and OS X.
> > > 
> > > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I found something else (I know, I should stop :)). I am not entirely  
> > > > sure but it seems that when H5detect fails it writes "unable to calculate  
> > > > alignment for long double" on stderr so this message should be observable  
> > > > on build logs (although buried by other warnings). The packages on debian  
> > > > sid and testing for both i386 and x86-64 seem to be affected:
> > > > 
> > > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > > > 
> > > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > > 
> > > > But here's the exciting part: look what I found
> > > > 
> > > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > > 
> > > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > > > to calculate alignment for long double".
> > > > 
> > > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > > > problem and it would be that piece of code just doesn't work properly.
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > 
> > > > > Hi Ray,
> > > > > 
> > > > > thanks for giving it a look. Antonio made me notice that something else  
> > > > > might be at work since the macro DETECT\_F already zeroes the structure  
> > > > > right before anything else:
> > > > > 
> > > > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > > > 
> > > > > so I don't understand how the perm fields need to be zeroed again  
> > > > > around line #L308. This still considering the "Byte Order" loop as a black  
> > > > > box.
> > > > > 
> > > > > As a side question: isn't there a more portable way of doing this? I am  
> > > > > pretty sure H5detect.c might invoke a bunch of undefined behaviours given  
> > > > > the amount of warning the compiler generates and of bit trickery.
> > > > > 
> > > > > Best wishes,  
> > > > > Andrea
> > > > > 
> > > > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > > 
> > > > > > Andrea,
> > > > > > 
> > > > > > We've verified that your solution is correct. We're putting your fix  
> > > > > > into the library. Thanks for helping us.
> > > > > > 
> > > > > > Ray
> > > > > > 
> > > > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > > > 
> > > > > > Hi there,
> > > > > > 
> > > > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > > > 
> > > > > > Best wishes,  
> > > > > > Andrea
> > > > > > 
> > > > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > > > 
> > > > > > > Consider this very simple test
> > > > > > > 
> > > > > > > #include \<hdf5.h\>
> > > > > > > 
> > > > > > > int main() {  
> > > > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > &nbsp;&nbsp;default:  
> > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > > > &nbsp;&nbsp;}  
> > > > > > > &nbsp;&nbsp;return 0;  
> > > > > > > }
> > > > > > > 
> > > > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > > > 
> > > > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > > > 
> > > > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > > > 
> > > > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > > > definitions in src/H5Tinit.c  
> > > > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > > > > 
> > > > > > > I think this must be related to the failure of dt\_arith long double  
> > > > > > > test observed recently.
> > > > > > > 
> > > > > > > Any suggestion on how to fix this ?
> > > > > > > 
> > > > > > > Best wishes,  
> > > > > > > Andrea
> > > > > > > 
> > > > > > > --  
> > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > 
> > > > > > --  
> > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > > \<hdf5\_uninitialized.patch\>  
> > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > 
> > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > 
> > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > 
> > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > 
> > > > > --  
> > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > 
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > George N. White III \<aa056@chebucto.ns.ca\>  
> > > Head of St. Margarets Bay, Nova Scotia
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 6, 2013, 7:20am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/10 "2013-09-06T07:20:19Z")

</div>

Some links on memset (in the opposite order I have found them)

> **[Zero and forget -- caveats of zeroing memory in C](https://news.ycombinator.com/item?id=4711346)**

> **[eliteraspberries.com](http://www.eliteraspberries.com/blog/2012/10/zero-and-forget--caveats-of-zeroing-memory-in-c.html)**
>
> This domain may be for sale!

> **[Security, security! But do you test it?](https://pvs-studio.com/en/blog/posts/cpp/0178/)**
>
> There is no fragment in program code where you cannot make mistakes. You may actually make them in very simple fragments. While programmers have worked out the habit of testing algorithms, data...

> <https://stackoverflow.com/questions/15538366/can-memset-function-call-be-removed-by-compiler>

> **···**
>
> On 6 September 2013 16:49, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> 
> > Hi Rey,
> > 
> > thanks for that, it really helped. I checked thoroughly and the memset of  
> > the temporary variables disappears randomly.  
> > It doesn't depends only on optimization though, on my machine putting a  
> > printf("%Lf\n", value2); just before the loop changes the result.  
> > I'm not sure who gets the blame here, poking into the padding bits of a  
> > long double might just be unspecified or undefined behaviour.
> > 
> > Andrea
> > 
> > On 6 September 2013 06:40, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > 
> > > I isolated part of the DETECT\_F into a C program as attached (detect.c).  
> > > It only contains the algorithm for detecting the byte order of long  
> > > double. When I compile it with gcc -g, -O0, or no flag, it reports  
> > > little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX  
> > > order. I don't know where goes wrong yet. But I suspect GCC's  
> > > optimization has bugs. Maybe you can help me.
> > > 
> > > I haven't tried the algorithms for other parts in DETECT\_F yet. The  
> > > alignment problem you talked about is one of the other algorithms.
> > > 
> > > Ray
> > > 
> > > On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> > > 
> > > Thanks George.
> > > 
> > > For anyone interested in debugging this problem, debian has an extensive  
> > > collection of build logs over many architectures  
> > > [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)
> > > 
> > > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE  
> > > type. You can check your particular build with the following test
> > > 
> > > #include \<hdf5.h\>  
> > > int main() {  
> > > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(  
> > > H5T\_NATIVE\_DOUBLE));  
> > > }
> > > 
> > > It exits with code 1 if the long double has different byte ordering than  
> > > double (which is technically possible, but highly suspicious).
> > > 
> > > Otherwise the patch I sent earlier in this thread seems to do the trick,  
> > > although what exactly is going wrong is still beyond my understanding.
> > > 
> > > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE  
> > > yourself. The following creates a data type representing a long double as  
> > > implemented by gcc on x86 architectures (see  
> > > [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > > 
> > > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > > H5Tset\_precision(ldouble\_datatype, 80);  
> > > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:
> > > 
> > > > Another historical reference to the obscurity of this code is: \<  
> > > > [118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > > > 
> > > > I've been building HDF5 libraries for use with NASA SeaDAS, and recently  
> > > > have started using HDF5 with R and GDAL. The SeaDAS builds are static, and  
> > > > I don't find the "unable to calculate alignment for long double" message in  
> > > > my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need  
> > > > dynamic libraries and those build logs do have the "unable to calculate  
> > > > alignment for long double" message on both linux and OS X.
> > > > 
> > > > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I found something else (I know, I should stop :)). I am not entirely  
> > > > > sure but it seems that when H5detect fails it writes "unable to calculate  
> > > > > alignment for long double" on stderr so this message should be observable  
> > > > > on build logs (although buried by other warnings). The packages on debian  
> > > > > sid and testing for both i386 and x86-64 seem to be affected:
> > > > > 
> > > > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > > > > 
> > > > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > > > 
> > > > > But here's the exciting part: look what I found
> > > > > 
> > > > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > > > 
> > > > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > > > > to calculate alignment for long double".
> > > > > 
> > > > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > > > > problem and it would be that piece of code just doesn't work properly.
> > > > > 
> > > > > Best wishes,  
> > > > > Andrea
> > > > > 
> > > > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > 
> > > > > > Hi Ray,
> > > > > > 
> > > > > > thanks for giving it a look. Antonio made me notice that something  
> > > > > > else might be at work since the macro DETECT\_F already zeroes the structure  
> > > > > > right before anything else:
> > > > > > 
> > > > > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > > > > 
> > > > > > so I don't understand how the perm fields need to be zeroed again  
> > > > > > around line #L308. This still considering the "Byte Order" loop as a black  
> > > > > > box.
> > > > > > 
> > > > > > As a side question: isn't there a more portable way of doing this? I  
> > > > > > am pretty sure H5detect.c might invoke a bunch of undefined behaviours  
> > > > > > given the amount of warning the compiler generates and of bit trickery.
> > > > > > 
> > > > > > Best wishes,  
> > > > > > Andrea
> > > > > > 
> > > > > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > > > 
> > > > > > > Andrea,
> > > > > > > 
> > > > > > > We've verified that your solution is correct. We're putting your fix  
> > > > > > > into the library. Thanks for helping us.
> > > > > > > 
> > > > > > > Ray
> > > > > > > 
> > > > > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > > > > 
> > > > > > > Hi there,
> > > > > > > 
> > > > > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > > > > 
> > > > > > > Best wishes,  
> > > > > > > Andrea
> > > > > > > 
> > > > > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > > > > 
> > > > > > > > Consider this very simple test
> > > > > > > > 
> > > > > > > > #include \<hdf5.h\>
> > > > > > > > 
> > > > > > > > int main() {  
> > > > > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;default:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > > > > &nbsp;&nbsp;}  
> > > > > > > > &nbsp;&nbsp;return 0;  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > > > > 
> > > > > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > > > > 
> > > > > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > > > > 
> > > > > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > > > > definitions in src/H5Tinit.c  
> > > > > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > > > > > 
> > > > > > > > I think this must be related to the failure of dt\_arith long double  
> > > > > > > > test observed recently.
> > > > > > > > 
> > > > > > > > Any suggestion on how to fix this ?
> > > > > > > > 
> > > > > > > > Best wishes,  
> > > > > > > > Andrea
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > > 
> > > > > > > --  
> > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > > > \<hdf5\_uninitialized.patch\>  
> > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > 
> > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > > 
> > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > 
> > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > 
> > > > > > --  
> > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > 
> > > > > --  
> > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > 
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > --  
> > > > George N. White III \<aa056@chebucto.ns.ca\>  
> > > > Head of St. Margarets Bay, Nova Scotia
> > > > 
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Raymond\_Lu](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@Raymond\_Lu](https://forum.hdfgroup.org/u/Raymond_Lu)\
**Post date:** [September 6, 2013, 10:24pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/11 "2013-09-06T22:24:30Z")

</div>

Andrea,

My coworker Neil helped me in this afternoon to find out that when GCC 4.8 compiler assigns constant values to variables (value1 and value2) like this,

&nbsp;&nbsp;&nbsp;for(i = 0, value1 = 0.0, value2 = 1.0; i \< (int)sizeof(long double); i++) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= 256.0;  
&nbsp;&nbsp;&nbsp;&nbsp;:  
&nbsp;&nbsp;&nbsp;&nbsp;:

it introduces some garbage to the two padding bytes of value1 and value2. Then the garbage confuses our algorithm, especially the value of "last\_mbyte" gets wrong. To fix it in a simple way, use an intermediate variable like this:

&nbsp;&nbsp;&nbsp;long double tmp\_value, divisor;

&nbsp;&nbsp;&nbsp;tmp\_value = 0.0;  
&nbsp;&nbsp;&nbsp;value1 = tmp\_value;  
&nbsp;&nbsp;&nbsp;tmp\_value = 1.0;  
&nbsp;&nbsp;&nbsp;value2 = tmp\_value;  
&nbsp;&nbsp;&nbsp;tmp\_value = 256.0;  
&nbsp;&nbsp;&nbsp;divisor = tmp\_value;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;for(i = 0; i \< (int)sizeof(long double); i++) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= divisor;  
&nbsp;&nbsp;&nbsp;&nbsp;:  
&nbsp;&nbsp;&nbsp;&nbsp;:

How do you think about it?

Ray

> **···**
>
> On Sep 6, 2013, at 1:49 AM, Andrea Bedini wrote:
> 
> > Hi Rey,
> > 
> > thanks for that, it really helped. I checked thoroughly and the memset of the temporary variables disappears randomly.  
> > It doesn't depends only on optimization though, on my machine putting a printf("%Lf\n", value2); just before the loop changes the result.  
> > I'm not sure who gets the blame here, poking into the padding bits of a long double might just be unspecified or undefined behaviour.
> > 
> > Andrea
> > 
> > On 6 September 2013 06:40, Raymond Lu \<songyulu@hdfgroup.org\> wrote:  
> > I isolated part of the DETECT\_F into a C program as attached (detect.c). It only contains the algorithm for detecting the byte order of long double. When I compile it with gcc -g, -O0, or no flag, it reports little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX order. I don't know where goes wrong yet. But I suspect GCC's optimization has bugs. Maybe you can help me.
> > 
> > I haven't tried the algorithms for other parts in DETECT\_F yet. The alignment problem you talked about is one of the other algorithms.
> > 
> > Ray
> > 
> > On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> > 
> > > Thanks George.
> > > 
> > > For anyone interested in debugging this problem, debian has an extensive collection of build logs over many architectures [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)
> > > 
> > > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE type. You can check your particular build with the following test
> > > 
> > > #include \<hdf5.h\>  
> > > int main() {  
> > > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(H5T\_NATIVE\_DOUBLE));  
> > > }
> > > 
> > > It exits with code 1 if the long double has different byte ordering than double (which is technically possible, but highly suspicious).
> > > 
> > > Otherwise the patch I sent earlier in this thread seems to do the trick, although what exactly is going wrong is still beyond my understanding.
> > > 
> > > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE yourself. The following creates a data type representing a long double as implemented by gcc on x86 architectures (see [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > > 
> > > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > > H5Tset\_precision(ldouble\_datatype, 80);  
> > > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:  
> > > Another historical reference to the obscurity of this code is: \<[118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > > 
> > > I've been building HDF5 libraries for use with NASA SeaDAS, and recently have started using HDF5 with R and GDAL. The SeaDAS builds are static, and I don't find the "unable to calculate alignment for long double" message in my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need dynamic libraries and those build logs do have the "unable to calculate alignment for long double" message on both linux and OS X.
> > > 
> > > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > > Hi,
> > > 
> > > I found something else (I know, I should stop :)). I am not entirely sure but it seems that when H5detect fails it writes "unable to calculate alignment for long double" on stderr so this message should be observable on build logs (although buried by other warnings). The packages on debian sid and testing for both i386 and x86-64 seem to be affected:
> > > 
> > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)  
> > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > 
> > > But here's the exciting part: look what I found
> > > 
> > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > 
> > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable to calculate alignment for long double".
> > > 
> > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the problem and it would be that piece of code just doesn't work properly.
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > > Hi Ray,
> > > 
> > > thanks for giving it a look. Antonio made me notice that something else might be at work since the macro DETECT\_F already zeroes the structure right before anything else:
> > > 
> > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > 
> > > so I don't understand how the perm fields need to be zeroed again around line #L308. This still considering the "Byte Order" loop as a black box.
> > > 
> > > As a side question: isn't there a more portable way of doing this? I am pretty sure H5detect.c might invoke a bunch of undefined behaviours given the amount of warning the compiler generates and of bit trickery.
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:  
> > > Andrea,
> > > 
> > > We've verified that your solution is correct. We're putting your fix into the library. Thanks for helping us.
> > > 
> > > Ray
> > > 
> > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > 
> > > > Hi there,
> > > > 
> > > > I think I have found the problem. The issue is in H5detect.c. Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in the detected\_t struct. As a result the routine fix\_order is passed some uninitialized memory which makes it fail. I have a small patch against H5detect.c which fixes the problem by simply initializing the perm field with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:  
> > > > Hi,
> > > > 
> > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > 
> > > > Consider this very simple test
> > > > 
> > > > #include \<hdf5.h\>
> > > > 
> > > > int main() {  
> > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > &nbsp;&nbsp;default:  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > &nbsp;&nbsp;}  
> > > > &nbsp;&nbsp;return 0;  
> > > > }
> > > > 
> > > > on the same x86\_64 GNU/Linux machine I get
> > > > 
> > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > 
> > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > 
> > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and basically the fault must be in src/H5detect.c which is used to generate the definitions in src/H5Tinit.c  
> > > > I could not figure out what H5detect.c does wrong (it is not very readable, given its extensive use of macros) but the compiler does emit a lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > 
> > > > I think this must be related to the failure of dt\_arith long double test observed recently.
> > > > 
> > > > Any suggestion on how to fix this ?
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > \<hdf5\_uninitialized.patch\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org  
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org  
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org  
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > George N. White III \<aa056@chebucto.ns.ca\>  
> > > Head of St. Margarets Bay, Nova Scotia
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org  
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org  
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 7, 2013, 12:04am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/12 "2013-09-07T00:04:15Z")

</div>

Hi Ray,

yes, this is compatible with what I observed in my tests. Honestly I am not  
sure the problem has a simple solution at all. If the standard doesn't  
guarantee us the pad bit have a consistent value, there's no way we can  
expect this to work in a portable way: at some point in the future a  
compiler will be smart enough to revert all the obstacles we throw at its  
way.

If I may, I would suggest we replace the entire mechanism with something  
simpler. There are not that many floating point formats floating around  
(pardon the pun), even considering the many architectures. Can't we just  
hardcode them? The configuration system has surely enough information to  
determine the native floating point format without bit fiddling.

What are the supported architectures?

Andrea

PS: it seems the disappearing memset problem can be solved by asking gcc to  
not replace memset with its builtin version, i.e. passing the option  
-fno-builtin-memset, but this of course won't work with other compilers.

> **···**
>
> On 7 September 2013 08:24, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> 
> > Andrea,
> > 
> > My coworker Neil helped me in this afternoon to find out that when GCC 4.8  
> > compiler assigns constant values to variables (value1 and value2) like this,
> > 
> > &nbsp;&nbsp;&nbsp;for(i = 0, value1 = 0.0, value2 = 1.0; i \< (int)sizeof(long double);  
> > i++) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= 256.0;  
> > :  
> > :
> > 
> > it introduces some garbage to the two padding bytes of value1 and value2.  
> > Then the garbage confuses our algorithm, especially the value of  
> > "last\_mbyte" gets wrong. To fix it in a simple way, use an intermediate  
> > variable like this:
> > 
> > &nbsp;&nbsp;&nbsp;long double tmp\_value, divisor;
> > 
> > &nbsp;&nbsp;&nbsp;tmp\_value = 0.0;  
> > &nbsp;&nbsp;&nbsp;value1 = tmp\_value;  
> > &nbsp;&nbsp;&nbsp;tmp\_value = 1.0;  
> > &nbsp;&nbsp;&nbsp;value2 = tmp\_value;  
> > &nbsp;&nbsp;&nbsp;tmp\_value = 256.0;  
> > &nbsp;&nbsp;&nbsp;divisor = tmp\_value;
> > 
> > &nbsp;&nbsp;&nbsp;for(i = 0; i \< (int)sizeof(long double); i++) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= divisor;  
> > :  
> > :
> > 
> > How do you think about it?
> > 
> > Ray
> > 
> > On Sep 6, 2013, at 1:49 AM, Andrea Bedini wrote:
> > 
> > Hi Rey,
> > 
> > thanks for that, it really helped. I checked thoroughly and the memset of  
> > the temporary variables disappears randomly.  
> > It doesn't depends only on optimization though, on my machine putting a  
> > printf("%Lf\n", value2); just before the loop changes the result.  
> > I'm not sure who gets the blame here, poking into the padding bits of a  
> > long double might just be unspecified or undefined behaviour.
> > 
> > Andrea
> > 
> > On 6 September 2013 06:40, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > 
> > > I isolated part of the DETECT\_F into a C program as attached (detect.c).  
> > > It only contains the algorithm for detecting the byte order of long  
> > > double. When I compile it with gcc -g, -O0, or no flag, it reports  
> > > little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX  
> > > order. I don't know where goes wrong yet. But I suspect GCC's  
> > > optimization has bugs. Maybe you can help me.
> > > 
> > > I haven't tried the algorithms for other parts in DETECT\_F yet. The  
> > > alignment problem you talked about is one of the other algorithms.
> > > 
> > > Ray
> > > 
> > > On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> > > 
> > > Thanks George.
> > > 
> > > For anyone interested in debugging this problem, debian has an extensive  
> > > collection of build logs over many architectures  
> > > [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)
> > > 
> > > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE  
> > > type. You can check your particular build with the following test
> > > 
> > > #include \<hdf5.h\>  
> > > int main() {  
> > > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(  
> > > H5T\_NATIVE\_DOUBLE));  
> > > }
> > > 
> > > It exits with code 1 if the long double has different byte ordering than  
> > > double (which is technically possible, but highly suspicious).
> > > 
> > > Otherwise the patch I sent earlier in this thread seems to do the trick,  
> > > although what exactly is going wrong is still beyond my understanding.
> > > 
> > > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE  
> > > yourself. The following creates a data type representing a long double as  
> > > implemented by gcc on x86 architectures (see  
> > > [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > > 
> > > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > > H5Tset\_precision(ldouble\_datatype, 80);  
> > > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > > 
> > > Best wishes,  
> > > Andrea
> > > 
> > > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:
> > > 
> > > > Another historical reference to the obscurity of this code is: \<  
> > > > [118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > > > 
> > > > I've been building HDF5 libraries for use with NASA SeaDAS, and recently  
> > > > have started using HDF5 with R and GDAL. The SeaDAS builds are static, and  
> > > > I don't find the "unable to calculate alignment for long double" message in  
> > > > my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need  
> > > > dynamic libraries and those build logs do have the "unable to calculate  
> > > > alignment for long double" message on both linux and OS X.
> > > > 
> > > > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I found something else (I know, I should stop :)). I am not entirely  
> > > > > sure but it seems that when H5detect fails it writes "unable to calculate  
> > > > > alignment for long double" on stderr so this message should be observable  
> > > > > on build logs (although buried by other warnings). The packages on debian  
> > > > > sid and testing for both i386 and x86-64 seem to be affected:
> > > > > 
> > > > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > > > > 
> > > > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > > > 
> > > > > But here's the exciting part: look what I found
> > > > > 
> > > > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > > > 
> > > > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > > > > to calculate alignment for long double".
> > > > > 
> > > > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > > > > problem and it would be that piece of code just doesn't work properly.
> > > > > 
> > > > > Best wishes,  
> > > > > Andrea
> > > > > 
> > > > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > 
> > > > > > Hi Ray,
> > > > > > 
> > > > > > thanks for giving it a look. Antonio made me notice that something  
> > > > > > else might be at work since the macro DETECT\_F already zeroes the structure  
> > > > > > right before anything else:
> > > > > > 
> > > > > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > > > > 
> > > > > > so I don't understand how the perm fields need to be zeroed again  
> > > > > > around line #L308. This still considering the "Byte Order" loop as a black  
> > > > > > box.
> > > > > > 
> > > > > > As a side question: isn't there a more portable way of doing this? I  
> > > > > > am pretty sure H5detect.c might invoke a bunch of undefined behaviours  
> > > > > > given the amount of warning the compiler generates and of bit trickery.
> > > > > > 
> > > > > > Best wishes,  
> > > > > > Andrea
> > > > > > 
> > > > > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > > > 
> > > > > > > Andrea,
> > > > > > > 
> > > > > > > We've verified that your solution is correct. We're putting your fix  
> > > > > > > into the library. Thanks for helping us.
> > > > > > > 
> > > > > > > Ray
> > > > > > > 
> > > > > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > > > > 
> > > > > > > Hi there,
> > > > > > > 
> > > > > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > > > > 
> > > > > > > Best wishes,  
> > > > > > > Andrea
> > > > > > > 
> > > > > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > > > > 
> > > > > > > > Consider this very simple test
> > > > > > > > 
> > > > > > > > #include \<hdf5.h\>
> > > > > > > > 
> > > > > > > > int main() {  
> > > > > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > &nbsp;&nbsp;default:  
> > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > > > > &nbsp;&nbsp;}  
> > > > > > > > &nbsp;&nbsp;return 0;  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > > > > 
> > > > > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > > > > 
> > > > > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > > > > 
> > > > > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > > > > definitions in src/H5Tinit.c  
> > > > > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > > > > > 
> > > > > > > > I think this must be related to the failure of dt\_arith long double  
> > > > > > > > test observed recently.
> > > > > > > > 
> > > > > > > > Any suggestion on how to fix this ?
> > > > > > > > 
> > > > > > > > Best wishes,  
> > > > > > > > Andrea
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > > 
> > > > > > > --  
> > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > > > \<hdf5\_uninitialized.patch\>  
> > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > 
> > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > > 
> > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > 
> > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > 
> > > > > > --  
> > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > 
> > > > > --  
> > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > 
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > --  
> > > > George N. White III \<aa056@chebucto.ns.ca\>  
> > > > Head of St. Margarets Bay, Nova Scotia
> > > > 
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Andrea\_Bedini](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Andrea\_Bedini](https://forum.hdfgroup.org/u/Andrea_Bedini)\
**Post date:** [September 8, 2013, 11:58pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/13 "2013-09-08T23:58:56Z")

</div>

FYI I asked this question on stackoverflow.

> <https://stackoverflow.com/questions/18668871/accessing-long-double-bit-representation>

> **···**
>
> On 7 September 2013 10:04, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> 
> > Hi Ray,
> > 
> > yes, this is compatible with what I observed in my tests. Honestly I am  
> > not sure the problem has a simple solution at all. If the standard doesn't  
> > guarantee us the pad bit have a consistent value, there's no way we can  
> > expect this to work in a portable way: at some point in the future a  
> > compiler will be smart enough to revert all the obstacles we throw at its  
> > way.
> > 
> > If I may, I would suggest we replace the entire mechanism with something  
> > simpler. There are not that many floating point formats floating around  
> > (pardon the pun), even considering the many architectures. Can't we just  
> > hardcode them? The configuration system has surely enough information to  
> > determine the native floating point format without bit fiddling.
> > 
> > What are the supported architectures?
> > 
> > Andrea
> > 
> > PS: it seems the disappearing memset problem can be solved by asking gcc  
> > to not replace memset with its builtin version, i.e. passing the option  
> > -fno-builtin-memset, but this of course won't work with other compilers.
> > 
> > On 7 September 2013 08:24, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > 
> > > Andrea,
> > > 
> > > My coworker Neil helped me in this afternoon to find out that when GCC  
> > > 4.8 compiler assigns constant values to variables (value1 and value2) like  
> > > this,
> > > 
> > > &nbsp;&nbsp;&nbsp;for(i = 0, value1 = 0.0, value2 = 1.0; i \< (int)sizeof(long double);  
> > > i++) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= 256.0;  
> > > :  
> > > :
> > > 
> > > it introduces some garbage to the two padding bytes of value1 and value2.  
> > > Then the garbage confuses our algorithm, especially the value of  
> > > "last\_mbyte" gets wrong. To fix it in a simple way, use an intermediate  
> > > variable like this:
> > > 
> > > &nbsp;&nbsp;&nbsp;long double tmp\_value, divisor;
> > > 
> > > &nbsp;&nbsp;&nbsp;tmp\_value = 0.0;  
> > > &nbsp;&nbsp;&nbsp;value1 = tmp\_value;  
> > > &nbsp;&nbsp;&nbsp;tmp\_value = 1.0;  
> > > &nbsp;&nbsp;&nbsp;value2 = tmp\_value;  
> > > &nbsp;&nbsp;&nbsp;tmp\_value = 256.0;  
> > > &nbsp;&nbsp;&nbsp;divisor = tmp\_value;
> > > 
> > > &nbsp;&nbsp;&nbsp;for(i = 0; i \< (int)sizeof(long double); i++) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= divisor;  
> > > :  
> > > :
> > > 
> > > How do you think about it?
> > > 
> > > Ray
> > > 
> > > On Sep 6, 2013, at 1:49 AM, Andrea Bedini wrote:
> > > 
> > > Hi Rey,
> > > 
> > > thanks for that, it really helped. I checked thoroughly and the memset of  
> > > the temporary variables disappears randomly.  
> > > It doesn't depends only on optimization though, on my machine putting a  
> > > printf("%Lf\n", value2); just before the loop changes the result.  
> > > I'm not sure who gets the blame here, poking into the padding bits of a  
> > > long double might just be unspecified or undefined behaviour.
> > > 
> > > Andrea
> > > 
> > > On 6 September 2013 06:40, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > 
> > > > I isolated part of the DETECT\_F into a C program as attached (detect.c).  
> > > > It only contains the algorithm for detecting the byte order of long  
> > > > double. When I compile it with gcc -g, -O0, or no flag, it reports  
> > > > little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX  
> > > > order. I don't know where goes wrong yet. But I suspect GCC's  
> > > > optimization has bugs. Maybe you can help me.
> > > > 
> > > > I haven't tried the algorithms for other parts in DETECT\_F yet. The  
> > > > alignment problem you talked about is one of the other algorithms.
> > > > 
> > > > Ray
> > > > 
> > > > On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> > > > 
> > > > Thanks George.
> > > > 
> > > > For anyone interested in debugging this problem, debian has an extensive  
> > > > collection of build logs over many architectures  
> > > > [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12  
> > > > years!)
> > > > 
> > > > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE  
> > > > type. You can check your particular build with the following test
> > > > 
> > > > #include \<hdf5.h\>  
> > > > int main() {  
> > > > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(  
> > > > H5T\_NATIVE\_DOUBLE));  
> > > > }
> > > > 
> > > > It exits with code 1 if the long double has different byte ordering than  
> > > > double (which is technically possible, but highly suspicious).
> > > > 
> > > > Otherwise the patch I sent earlier in this thread seems to do the trick,  
> > > > although what exactly is going wrong is still beyond my understanding.
> > > > 
> > > > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE  
> > > > yourself. The following creates a data type representing a long double as  
> > > > implemented by gcc on x86 architectures (see  
> > > > [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > > > 
> > > > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > > > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > > > H5Tset\_precision(ldouble\_datatype, 80);  
> > > > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > > > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > > > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > > > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > > > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > > > 
> > > > Best wishes,  
> > > > Andrea
> > > > 
> > > > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\> wrote:
> > > > 
> > > > > Another historical reference to the obscurity of this code is: \<  
> > > > > [118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > > > > 
> > > > > I've been building HDF5 libraries for use with NASA SeaDAS, and  
> > > > > recently have started using HDF5 with R and GDAL. The SeaDAS builds are  
> > > > > static, and I don't find the "unable to calculate alignment for long  
> > > > > double" message in my SeaDAS build logs on linux and OS X. For R and GDAL,  
> > > > > however, I need dynamic libraries and those build logs do have the "unable  
> > > > > to calculate alignment for long double" message on both linux and OS X.
> > > > > 
> > > > > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I found something else (I know, I should stop :)). I am not entirely  
> > > > > > sure but it seems that when H5detect fails it writes "unable to calculate  
> > > > > > alignment for long double" on stderr so this message should be observable  
> > > > > > on build logs (although buried by other warnings). The packages on debian  
> > > > > > sid and testing for both i386 and x86-64 seem to be affected:
> > > > > > 
> > > > > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > > > > > 
> > > > > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > > > > 
> > > > > > But here's the exciting part: look what I found
> > > > > > 
> > > > > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > > > > 
> > > > > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > > > > > to calculate alignment for long double".
> > > > > > 
> > > > > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > > > > > problem and it would be that piece of code just doesn't work properly.
> > > > > > 
> > > > > > Best wishes,  
> > > > > > Andrea
> > > > > > 
> > > > > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > 
> > > > > > > Hi Ray,
> > > > > > > 
> > > > > > > thanks for giving it a look. Antonio made me notice that something  
> > > > > > > else might be at work since the macro DETECT\_F already zeroes the structure  
> > > > > > > right before anything else:
> > > > > > > 
> > > > > > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > > > > > 
> > > > > > > so I don't understand how the perm fields need to be zeroed again  
> > > > > > > around line #L308. This still considering the "Byte Order" loop as a black  
> > > > > > > box.
> > > > > > > 
> > > > > > > As a side question: isn't there a more portable way of doing this? I  
> > > > > > > am pretty sure H5detect.c might invoke a bunch of undefined behaviours  
> > > > > > > given the amount of warning the compiler generates and of bit trickery.
> > > > > > > 
> > > > > > > Best wishes,  
> > > > > > > Andrea
> > > > > > > 
> > > > > > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > > > > 
> > > > > > > > Andrea,
> > > > > > > > 
> > > > > > > > We've verified that your solution is correct. We're putting your  
> > > > > > > > fix into the library. Thanks for helping us.
> > > > > > > > 
> > > > > > > > Ray
> > > > > > > > 
> > > > > > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > > > > > 
> > > > > > > > Hi there,
> > > > > > > > 
> > > > > > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > > > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > > > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > > > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > > > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > > > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > > > > > 
> > > > > > > > Best wishes,  
> > > > > > > > Andrea
> > > > > > > > 
> > > > > > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > > > 
> > > > > > > > > Hi,
> > > > > > > > > 
> > > > > > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > > > > > 
> > > > > > > > > Consider this very simple test
> > > > > > > > > 
> > > > > > > > > #include \<hdf5.h\>
> > > > > > > > > 
> > > > > > > > > int main() {  
> > > > > > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > &nbsp;&nbsp;default:  
> > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > > > > > &nbsp;&nbsp;}  
> > > > > > > > > &nbsp;&nbsp;return 0;  
> > > > > > > > > }
> > > > > > > > > 
> > > > > > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > > > > > 
> > > > > > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > > > > > 
> > > > > > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > > > > > 
> > > > > > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > > > > > definitions in src/H5Tinit.c  
> > > > > > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > > > > > lot of warnings (see [https://gist.github.com/andreabedini/6419975\](https://gist.github.com/andreabedini/6419975%5C)).
> > > > > > > > > 
> > > > > > > > > I think this must be related to the failure of dt\_arith long double  
> > > > > > > > > test observed recently.
> > > > > > > > > 
> > > > > > > > > Any suggestion on how to fix this ?
> > > > > > > > > 
> > > > > > > > > Best wishes,  
> > > > > > > > > Andrea
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > > > > \<hdf5\_uninitialized.patch\>  
> > > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > > 
> > > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > > > 
> > > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > > 
> > > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > > 
> > > > > > > --  
> > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > 
> > > > > > --  
> > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > 
> > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > 
> > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > 
> > > > > --  
> > > > > George N. White III \<aa056@chebucto.ns.ca\>  
> > > > > Head of St. Margarets Bay, Nova Scotia
> > > > > 
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > Hdf-forum is for HDF software users discussion.  
> > > Hdf-forum@lists.hdfgroup.org
> > > 
> > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> 
> --  
> Andrea Bedini \<andrea.bedini@gmail.com\>

---

<div class="post-metadata">

**Author:** ![gnwiii](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/g/e5b9ba/32.png) [@gnwiii](https://forum.hdfgroup.org/u/gnwiii)\
**Post date:** [September 9, 2013, 11:18am UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/14 "2013-09-09T11:18:59Z")

</div>

The answers to \<  
[c - accessing long double bit representation - Stack Overflow](http://stackoverflow.com/questions/18668871/accessing-long-double-bit-representation&gt);  
indicate that it is not safe to rely on the contents of padding bits.

The underlying problem here is to have a robust and standards compliant way  
to determine the alignment of various data types. This is a sufficiently  
important use case that there really should be a way to determine this  
without relying on the bits used for padding. Maybe there is a gap in the  
current standards that could be fixed in the future, but this problem  
affects a large number of existing workflows so needs to be addressed in a  
way that is compatible with legacy compilers/OS's. There is some merit to  
the idea of providing the information via a table, but such tables have a  
way of getting out of sync with reality. Would it be feasible to enumerate  
the most common alignment's and then apply a test that doesn't rely on the  
contents of the padding bits to select the appropriate entry from the table  
of possibilities?

> **···**
>
> On Sun, Sep 8, 2013 at 8:58 PM, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> 
> > FYI I asked this question on stackoverflow.
> > 
> > [c - accessing long double bit representation - Stack Overflow](http://stackoverflow.com/questions/18668871/accessing-long-double-bit-representation)
> > 
> > On 7 September 2013 10:04, Andrea Bedini \<andrea.bedini@gmail.com\> wrote:
> > 
> > > Hi Ray,
> > > 
> > > yes, this is compatible with what I observed in my tests. Honestly I am  
> > > not sure the problem has a simple solution at all. If the standard doesn't  
> > > guarantee us the pad bit have a consistent value, there's no way we can  
> > > expect this to work in a portable way: at some point in the future a  
> > > compiler will be smart enough to revert all the obstacles we throw at its  
> > > way.
> > > 
> > > If I may, I would suggest we replace the entire mechanism with something  
> > > simpler. There are not that many floating point formats floating around  
> > > (pardon the pun), even considering the many architectures. Can't we just  
> > > hardcode them? The configuration system has surely enough information to  
> > > determine the native floating point format without bit fiddling.
> > > 
> > > What are the supported architectures?
> > > 
> > > Andrea
> > > 
> > > PS: it seems the disappearing memset problem can be solved by asking gcc  
> > > to not replace memset with its builtin version, i.e. passing the option  
> > > -fno-builtin-memset, but this of course won't work with other compilers.
> > > 
> > > On 7 September 2013 08:24, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > 
> > > > Andrea,
> > > > 
> > > > My coworker Neil helped me in this afternoon to find out that when GCC  
> > > > 4.8 compiler assigns constant values to variables (value1 and value2) like  
> > > > this,
> > > > 
> > > > &nbsp;&nbsp;&nbsp;for(i = 0, value1 = 0.0, value2 = 1.0; i \< (int)sizeof(long double);  
> > > > i++) {  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= 256.0;  
> > > > :  
> > > > :
> > > > 
> > > > it introduces some garbage to the two padding bytes of value1 and  
> > > > value2. Then the garbage confuses our algorithm, especially the value of  
> > > > "last\_mbyte" gets wrong. To fix it in a simple way, use an intermediate  
> > > > variable like this:
> > > > 
> > > > &nbsp;&nbsp;&nbsp;long double tmp\_value, divisor;
> > > > 
> > > > &nbsp;&nbsp;&nbsp;tmp\_value = 0.0;  
> > > > &nbsp;&nbsp;&nbsp;value1 = tmp\_value;  
> > > > &nbsp;&nbsp;&nbsp;tmp\_value = 1.0;  
> > > > &nbsp;&nbsp;&nbsp;value2 = tmp\_value;  
> > > > &nbsp;&nbsp;&nbsp;tmp\_value = 256.0;  
> > > > &nbsp;&nbsp;&nbsp;divisor = tmp\_value;
> > > > 
> > > > &nbsp;&nbsp;&nbsp;for(i = 0; i \< (int)sizeof(long double); i++) {  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= divisor;  
> > > > :  
> > > > :
> > > > 
> > > > How do you think about it?
> > > > 
> > > > Ray
> > > > 
> > > > On Sep 6, 2013, at 1:49 AM, Andrea Bedini wrote:
> > > > 
> > > > Hi Rey,
> > > > 
> > > > thanks for that, it really helped. I checked thoroughly and the memset  
> > > > of the temporary variables disappears randomly.  
> > > > It doesn't depends only on optimization though, on my machine putting a  
> > > > printf("%Lf\n", value2); just before the loop changes the result.  
> > > > I'm not sure who gets the blame here, poking into the padding bits of a  
> > > > long double might just be unspecified or undefined behaviour.
> > > > 
> > > > Andrea
> > > > 
> > > > On 6 September 2013 06:40, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > 
> > > > > I isolated part of the DETECT\_F into a C program as attached  
> > > > > (detect.c). It only contains the algorithm for detecting the byte order of  
> > > > > long double. When I compile it with gcc -g, -O0, or no flag, it reports  
> > > > > little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX  
> > > > > order. I don't know where goes wrong yet. But I suspect GCC's  
> > > > > optimization has bugs. Maybe you can help me.
> > > > > 
> > > > > I haven't tried the algorithms for other parts in DETECT\_F yet. The  
> > > > > alignment problem you talked about is one of the other algorithms.
> > > > > 
> > > > > Ray
> > > > > 
> > > > > On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> > > > > 
> > > > > Thanks George.
> > > > > 
> > > > > For anyone interested in debugging this problem, debian has an  
> > > > > extensive collection of build logs over many architectures  
> > > > > [Build logs for hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12  
> > > > > years!)
> > > > > 
> > > > > As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE  
> > > > > type. You can check your particular build with the following test
> > > > > 
> > > > > #include \<hdf5.h\>  
> > > > > int main() {  
> > > > > &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(  
> > > > > H5T\_NATIVE\_DOUBLE));  
> > > > > }
> > > > > 
> > > > > It exits with code 1 if the long double has different byte ordering  
> > > > > than double (which is technically possible, but highly suspicious).
> > > > > 
> > > > > Otherwise the patch I sent earlier in this thread seems to do the  
> > > > > trick, although what exactly is going wrong is still beyond my  
> > > > > understanding.
> > > > > 
> > > > > Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE  
> > > > > yourself. The following creates a data type representing a long double as  
> > > > > implemented by gcc on x86 architectures (see  
> > > > > [long double - Wikipedia](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> > > > > 
> > > > > hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> > > > > H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> > > > > H5Tset\_precision(ldouble\_datatype, 80);  
> > > > > H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> > > > > H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> > > > > H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> > > > > H5Tset\_ebias(ldouble\_datatype, 16383);  
> > > > > H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> > > > > 
> > > > > Best wishes,  
> > > > > Andrea
> > > > > 
> > > > > On 4 September 2013 22:58, George N. White III \<gnwiii@gmail.com\>wrote:
> > > > > 
> > > > > > Another historical reference to the obscurity of this code is: \<  
> > > > > > [118777 – sci-libs/hdf5-1.6.2 (and 1.6.4) cannot build because of Bus error in H5detect](https://bugs.gentoo.org/show_bug.cgi?id=118777&gt;%5C).
> > > > > > 
> > > > > > I've been building HDF5 libraries for use with NASA SeaDAS, and  
> > > > > > recently have started using HDF5 with R and GDAL. The SeaDAS builds are  
> > > > > > static, and I don't find the "unable to calculate alignment for long  
> > > > > > double" message in my SeaDAS build logs on linux and OS X. For R and GDAL,  
> > > > > > however, I need dynamic libraries and those build logs do have the "unable  
> > > > > > to calculate alignment for long double" message on both linux and OS X.
> > > > > > 
> > > > > > On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<andrea.bedini@gmail.com \>\>\>\>\> \> wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > I found something else (I know, I should stop :)). I am not entirely  
> > > > > > > sure but it seems that when H5detect fails it writes "unable to calculate  
> > > > > > > alignment for long double" on stderr so this message should be observable  
> > > > > > > on build logs (although buried by other warnings). The packages on debian  
> > > > > > > sid and testing for both i386 and x86-64 seem to be affected:
> > > > > > > 
> > > > > > > [Build log for hdf5 (1.8.11-3+b1) on amd64](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)
> > > > > > > 
> > > > > > > [Build log for hdf5 (1.8.11-3+b1) on i386](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> > > > > > > 
> > > > > > > But here's the exciting part: look what I found
> > > > > > > 
> > > > > > > [[gembud] Problems compiling Gempak 5.11.4 on Fedora 12](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> > > > > > > 
> > > > > > > It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable  
> > > > > > > to calculate alignment for long double".
> > > > > > > 
> > > > > > > If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the  
> > > > > > > problem and it would be that piece of code just doesn't work properly.
> > > > > > > 
> > > > > > > Best wishes,  
> > > > > > > Andrea
> > > > > > > 
> > > > > > > On 4 September 2013 08:00, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > > 
> > > > > > > > Hi Ray,
> > > > > > > > 
> > > > > > > > thanks for giving it a look. Antonio made me notice that something  
> > > > > > > > else might be at work since the macro DETECT\_F already zeroes the structure  
> > > > > > > > right before anything else:
> > > > > > > > 
> > > > > > > > memset(&INFO, 0, sizeof(INFO)); #L299
> > > > > > > > 
> > > > > > > > so I don't understand how the perm fields need to be zeroed again  
> > > > > > > > around line #L308. This still considering the "Byte Order" loop as a black  
> > > > > > > > box.
> > > > > > > > 
> > > > > > > > As a side question: isn't there a more portable way of doing this? I  
> > > > > > > > am pretty sure H5detect.c might invoke a bunch of undefined behaviours  
> > > > > > > > given the amount of warning the compiler generates and of bit trickery.
> > > > > > > > 
> > > > > > > > Best wishes,  
> > > > > > > > Andrea
> > > > > > > > 
> > > > > > > > On 4 September 2013 05:43, Raymond Lu \<songyulu@hdfgroup.org\> wrote:
> > > > > > > > 
> > > > > > > > > Andrea,
> > > > > > > > > 
> > > > > > > > > We've verified that your solution is correct. We're putting your  
> > > > > > > > > fix into the library. Thanks for helping us.
> > > > > > > > > 
> > > > > > > > > Ray
> > > > > > > > > 
> > > > > > > > > On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> > > > > > > > > 
> > > > > > > > > Hi there,
> > > > > > > > > 
> > > > > > > > > I think I have found the problem. The issue is in H5detect.c.  
> > > > > > > > > Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in  
> > > > > > > > > the detected\_t struct. As a result the routine fix\_order is passed some  
> > > > > > > > > uninitialized memory which makes it fail. I have a small patch against  
> > > > > > > > > H5detect.c which fixes the problem by simply initializing the perm field  
> > > > > > > > > with zeros. Valgrind's tool memcheck would have exposed the problem.
> > > > > > > > > 
> > > > > > > > > Best wishes,  
> > > > > > > > > Andrea
> > > > > > > > > 
> > > > > > > > > On 3 September 2013 15:30, Andrea Bedini \<andrea.bedini@gmail.com\>wrote:
> > > > > > > > > 
> > > > > > > > > > Hi,
> > > > > > > > > > 
> > > > > > > > > > I am experiencing the following issue with hdf5 and gcc 4.8.0
> > > > > > > > > > 
> > > > > > > > > > Consider this very simple test
> > > > > > > > > > 
> > > > > > > > > > #include \<hdf5.h\>
> > > > > > > > > > 
> > > > > > > > > > int main() {  
> > > > > > > > > > &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> > > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > > &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;break;  
> > > > > > > > > > &nbsp;&nbsp;default:  
> > > > > > > > > > &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> > > > > > > > > > &nbsp;&nbsp;}  
> > > > > > > > > > &nbsp;&nbsp;return 0;  
> > > > > > > > > > }
> > > > > > > > > > 
> > > > > > > > > > on the same x86\_64 GNU/Linux machine I get
> > > > > > > > > > 
> > > > > > > > > > $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> > > > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> > > > > > > > > > 
> > > > > > > > > > $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> > > > > > > > > > H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> > > > > > > > > > 
> > > > > > > > > > So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and  
> > > > > > > > > > basically the fault must be in src/H5detect.c which is used to generate the  
> > > > > > > > > > definitions in src/H5Tinit.c  
> > > > > > > > > > I could not figure out what H5detect.c does wrong (it is not very  
> > > > > > > > > > readable, given its extensive use of macros) but the compiler does emit a  
> > > > > > > > > > lot of warnings (see [warnings I get compiling hdf5-1.8.11/src/H5detect.c with gcc-4.8.0 · GitHub](https://gist.github.com/andreabedini/6419975)  
> > > > > > > > > > ).
> > > > > > > > > > 
> > > > > > > > > > I think this must be related to the failure of dt\_arith long  
> > > > > > > > > > double test observed recently.
> > > > > > > > > > 
> > > > > > > > > > Any suggestion on how to fix this ?
> > > > > > > > > > 
> > > > > > > > > > Best wishes,  
> > > > > > > > > > Andrea
> > > > > > > > > > 
> > > > > > > > > > --  
> > > > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > > > > > \<hdf5\_uninitialized.patch\>  
> > > > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > > > 
> > > > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > > > > 
> > > > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > > > 
> > > > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > > 
> > > > > > > --  
> > > > > > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > > > > > > 
> > > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > > 
> > > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > > 
> > > > > > --  
> > > > > > George N. White III \<aa056@chebucto.ns.ca\>  
> > > > > > Head of St. Margarets Bay, Nova Scotia
> > > > > > 
> > > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > > Hdf-forum is for HDF software users discussion.  
> > > > > > Hdf-forum@lists.hdfgroup.org
> > > > > > 
> > > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > 
> > > > > --  
> > > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > > 
> > > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > > Hdf-forum is for HDF software users discussion.  
> > > > > Hdf-forum@lists.hdfgroup.org
> > > > > 
> > > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > --  
> > > > Andrea Bedini \<andrea.bedini@gmail.com\>  
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > > 
> > > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > > Hdf-forum is for HDF software users discussion.  
> > > > Hdf-forum@lists.hdfgroup.org
> > > > 
> > > > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > > 
> > > --  
> > > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > --  
> > Andrea Bedini \<andrea.bedini@gmail.com\>
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> George N. White III \<aa056@chebucto.ns.ca\>  
> Head of St. Margarets Bay, Nova Scotia

---

<div class="post-metadata">

**Author:** ![nfortne2](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/nfortne2/32/1543_2.png) [@nfortne2](https://forum.hdfgroup.org/u/nfortne2)\
**Post date:** [September 27, 2013, 3:48pm UTC](https://forum.hdfgroup.org/t/issues-with-h5t-native-ldouble/2991/15 "2013-09-27T15:48:53Z")

</div>

This issue has been fixed in 1.8.12. I fixed it by, before doing any other analysis, flipping each bit in the variable and checking to see if the value changed (with ==). Bits that do not change the value are then ignored in subsequent steps. Here is the relevant code for those interested:

&nbsp;&nbsp;&nbsp;&nbsp;volatile TYPE \_v1, \_v2;  
&nbsp;&nbsp;&nbsp;&nbsp;unsigned char \_buf1[sizeof(TYPE)];  
&nbsp;&nbsp;&nbsp;&nbsp;unsigned char \_pad\_mask[sizeof(TYPE)];  
&nbsp;&nbsp;&nbsp;&nbsp;unsigned char \_byte\_mask;  
&nbsp;&nbsp;&nbsp;&nbsp;int \_i;

\<...\>

&nbsp;&nbsp;&nbsp;&nbsp;\_v1 = 4.0;  
&nbsp;&nbsp;&nbsp;&nbsp;HDmemcpy(\_buf1, (const void \*)&\_v1, sizeof(TYPE));  
&nbsp;&nbsp;&nbsp;&nbsp;for(\_i = 0; \_i \< (int)sizeof(TYPE); \_i++)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(\_byte\_mask = (unsigned char)1; \_byte\_mask; \_byte\_mask \<\<= 1) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_buf1[\_i] ^= \_byte\_mask;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HDmemcpy((void \*)&\_v2, (const void \*)\_buf1, sizeof(TYPE));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(\_v1 != \_v2)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_pad\_mask[\_i] |= \_byte\_mask;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_buf1[\_i] ^= \_byte\_mask;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} /\* end for \*/

\<...\>

\_pad\_mask is then used to determine which bits to ignore when comparing variables in the subsequent analysis.

-Neil

> **···**
>
> On 09/09/2013 06:19 AM, George N. White III wrote:  
> The answers to \<[http://stackoverflow.com/questions/18668871/accessing-long-double-bit-representation](http://stackoverflow.com/questions/18668871/accessing-long-double-bit-representation)\> indicate that it is not safe to rely on the contents of padding bits.
> 
> The underlying problem here is to have a robust and standards compliant way to determine the alignment of various data types. This is a sufficiently important use case that there really should be a way to determine this without relying on the bits used for padding. Maybe there is a gap in the current standards that could be fixed in the future, but this problem affects a large number of existing workflows so needs to be addressed in a way that is compatible with legacy compilers/OS's. There is some merit to the idea of providing the information via a table, but such tables have a way of getting out of sync with reality. Would it be feasible to enumerate the most common alignment's and then apply a test that doesn't rely on the contents of the padding bits to select the appropriate entry from the table of possibilities?
> 
> On Sun, Sep 8, 2013 at 8:58 PM, Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\> wrote:  
> FYI I asked this question on stackoverflow.
> 
> > <https://stackoverflow.com/questions/18668871/accessing-long-double-bit-representation>
> 
> On 7 September 2013 10:04, Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\> wrote:  
> Hi Ray,
> 
> yes, this is compatible with what I observed in my tests. Honestly I am not sure the problem has a simple solution at all. If the standard doesn't guarantee us the pad bit have a consistent value, there's no way we can expect this to work in a portable way: at some point in the future a compiler will be smart enough to revert all the obstacles we throw at its way.
> 
> If I may, I would suggest we replace the entire mechanism with something simpler. There are not that many floating point formats floating around (pardon the pun), even considering the many architectures. Can't we just hardcode them? The configuration system has surely enough information to determine the native floating point format without bit fiddling.
> 
> What are the supported architectures?
> 
> Andrea
> 
> PS: it seems the disappearing memset problem can be solved by asking gcc to not replace memset with its builtin version, i.e. passing the option -fno-builtin-memset, but this of course won't work with other compilers.
> 
> On 7 September 2013 08:24, Raymond Lu \<[songyulu@hdfgroup.org](mailto:songyulu@hdfgroup.org)\<[mailto:songyulu@hdfgroup.org](mailto:songyulu@hdfgroup.org)\>\> wrote:  
> Andrea,
> 
> My coworker Neil helped me in this afternoon to find out that when GCC 4.8 compiler assigns constant values to variables (value1 and value2) like this,
> 
> &nbsp;&nbsp;&nbsp;for(i = 0, value1 = 0.0, value2 = 1.0; i \< (int)sizeof(long double); i++) {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= 256.0;  
> :  
> :
> 
> it introduces some garbage to the two padding bytes of value1 and value2. Then the garbage confuses our algorithm, especially the value of "last\_mbyte" gets wrong. To fix it in a simple way, use an intermediate variable like this:
> 
> &nbsp;&nbsp;&nbsp;long double tmp\_value, divisor;
> 
> &nbsp;&nbsp;&nbsp;tmp\_value = 0.0;  
> &nbsp;&nbsp;&nbsp;value1 = tmp\_value;  
> &nbsp;&nbsp;&nbsp;tmp\_value = 1.0;  
> &nbsp;&nbsp;&nbsp;value2 = tmp\_value;  
> &nbsp;&nbsp;&nbsp;tmp\_value = 256.0;  
> &nbsp;&nbsp;&nbsp;divisor = tmp\_value;
> 
> &nbsp;&nbsp;&nbsp;for(i = 0; i \< (int)sizeof(long double); i++) {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value3 = value1;  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value1 += value2;  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value2 /= divisor;  
> :  
> :
> 
> How do you think about it?
> 
> Ray
> 
> On Sep 6, 2013, at 1:49 AM, Andrea Bedini wrote:
> 
> Hi Rey,
> 
> thanks for that, it really helped. I checked thoroughly and the memset of the temporary variables disappears randomly.  
> It doesn't depends only on optimization though, on my machine putting a printf("%Lf\n", value2); just before the loop changes the result.  
> I'm not sure who gets the blame here, poking into the padding bits of a long double might just be unspecified or undefined behaviour.
> 
> Andrea
> 
> On 6 September 2013 06:40, Raymond Lu \<[songyulu@hdfgroup.org](mailto:songyulu@hdfgroup.org)\<[mailto:songyulu@hdfgroup.org](mailto:songyulu@hdfgroup.org)\>\> wrote:  
> I isolated part of the DETECT\_F into a C program as attached (detect.c). It only contains the algorithm for detecting the byte order of long double. When I compile it with gcc -g, -O0, or no flag, it reports little-endian. When I compile it with -O1, -O2, or -O3, it reports VAX order. I don't know where goes wrong yet. But I suspect GCC's optimization has bugs. Maybe you can help me.
> 
> I haven't tried the algorithms for other parts in DETECT\_F yet. The alignment problem you talked about is one of the other algorithms.
> 
> Ray
> 
> On Sep 4, 2013, at 8:40 PM, Andrea Bedini wrote:
> 
> Thanks George.
> 
> For anyone interested in debugging this problem, debian has an extensive collection of build logs over many architectures [https://buildd.debian.org/status/logs.php?pkg=hdf5](https://buildd.debian.org/status/logs.php?pkg=hdf5) (going back 12 years!)
> 
> As far as I know, the corruption is limited to the H5T\_NATIVE\_LDOUBLE type. You can check your particular build with the following test
> 
> #include \<hdf5.h\>  
> int main() {  
> &nbsp;&nbsp;return !(H5Tget\_order(H5T\_NATIVE\_LDOUBLE) == H5Tget\_order(H5T\_NATIVE\_DOUBLE));  
> }
> 
> It exits with code 1 if the long double has different byte ordering than double (which is technically possible, but highly suspicious).
> 
> Otherwise the patch I sent earlier in this thread seems to do the trick, although what exactly is going wrong is still beyond my understanding.
> 
> Third option: you can define an equivalent of H5T\_NATIVE\_LDOUBLE yourself. The following creates a data type representing a long double as implemented by gcc on x86 architectures (see [http://en.wikipedia.org/wiki/Long\_double#Implementations](http://en.wikipedia.org/wiki/Long_double#Implementations) for details)
> 
> hid\_t ldouble\_datatype = H5Tcopy(H5T\_NATIVE\_DOUBLE);  
> H5Tset\_size(ldouble\_datatype, sizeof(long double));  
> H5Tset\_precision(ldouble\_datatype, 80);  
> H5Tset\_fields (ldouble\_datatype, 79, 64, 15, 0, 64);  
> H5Tset\_pad(ldouble\_datatype, H5T\_PAD\_ZERO, H5T\_PAD\_ZERO);  
> H5Tset\_inpad(ldouble\_datatype, H5T\_PAD\_ZERO);  
> H5Tset\_ebias(ldouble\_datatype, 16383);  
> H5Tset\_norm(ldouble\_datatype, H5T\_NORM\_NONE);
> 
> Best wishes,  
> Andrea
> 
> On 4 September 2013 22:58, George N. White III \<[gnwiii@gmail.com](mailto:gnwiii@gmail.com)\<[mailto:gnwiii@gmail.com](mailto:gnwiii@gmail.com)\>\> wrote:  
> Another historical reference to the obscurity of this code is: \<[https://bugs.gentoo.org/show\_bug.cgi?id=118777](https://bugs.gentoo.org/show_bug.cgi?id=118777)\>.
> 
> I've been building HDF5 libraries for use with NASA SeaDAS, and recently have started using HDF5 with R and GDAL. The SeaDAS builds are static, and I don't find the "unable to calculate alignment for long double" message in my SeaDAS build logs on linux and OS X. For R and GDAL, however, I need dynamic libraries and those build logs do have the "unable to calculate alignment for long double" message on both linux and OS X.
> 
> On Tue, Sep 3, 2013 at 9:50 PM, Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\> wrote:  
> Hi,
> 
> I found something else (I know, I should stop :)). I am not entirely sure but it seems that when H5detect fails it writes "unable to calculate alignment for long double" on stderr so this message should be observable on build logs (although buried by other warnings). The packages on debian sid and testing for both i386 and x86-64 seem to be affected:
> 
> [https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=amd64&ver=1.8.11-3%2Bb1&stamp=1377024563)  
> [https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110](https://buildd.debian.org/status/fetch.php?pkg=hdf5&arch=i386&ver=1.8.11-3%2Bb1&stamp=1377025110)
> 
> But here's the exciting part: look what I found
> 
> [http://www.unidata.ucar.edu/mailing\_lists/archives/gembud/2010/msg00052.html](http://www.unidata.ucar.edu/mailing_lists/archives/gembud/2010/msg00052.html)
> 
> It's a build log from 2010 for HDF5 v1.6.5 and gcc-4.4.3 that says "unable to calculate alignment for long double".
> 
> If my understanding is correct, nor 1.8.11 or gcc 4.8.0 would be the problem and it would be that piece of code just doesn't work properly.
> 
> Best wishes,  
> Andrea
> 
> On 4 September 2013 08:00, Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\> wrote:  
> Hi Ray,
> 
> thanks for giving it a look. Antonio made me notice that something else might be at work since the macro DETECT\_F already zeroes the structure right before anything else:
> 
> memset(&INFO, 0, sizeof(INFO)); #L299
> 
> so I don't understand how the perm fields need to be zeroed again around line #L308. This still considering the "Byte Order" loop as a black box.
> 
> As a side question: isn't there a more portable way of doing this? I am pretty sure H5detect.c might invoke a bunch of undefined behaviours given the amount of warning the compiler generates and of bit trickery.
> 
> Best wishes,  
> Andrea
> 
> On 4 September 2013 05:43, Raymond Lu \<[songyulu@hdfgroup.org](mailto:songyulu@hdfgroup.org)\<[mailto:songyulu@hdfgroup.org](mailto:songyulu@hdfgroup.org)\>\> wrote:  
> Andrea,
> 
> We've verified that your solution is correct. We're putting your fix into the library. Thanks for helping us.
> 
> Ray
> 
> On Sep 3, 2013, at 3:32 AM, Andrea Bedini wrote:
> 
> Hi there,
> 
> I think I have found the problem. The issue is in H5detect.c. Macros DETECT\_F and DETECT\_I do not initialize properly the perm field in the detected\_t struct. As a result the routine fix\_order is passed some uninitialized memory which makes it fail. I have a small patch against H5detect.c which fixes the problem by simply initializing the perm field with zeros. Valgrind's tool memcheck would have exposed the problem.
> 
> Best wishes,  
> Andrea
> 
> On 3 September 2013 15:30, Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\> wrote:  
> Hi,
> 
> I am experiencing the following issue with hdf5 and gcc 4.8.0
> 
> Consider this very simple test
> 
> #include \<hdf5.h\>
> 
> int main() {  
> &nbsp;&nbsp;switch (H5Tget\_order(H5T\_NATIVE\_LDOUBLE)) {  
> &nbsp;&nbsp;case H5T\_ORDER\_LE:  
> &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE\n");  
> &nbsp;&nbsp;&nbsp;&nbsp;break;  
> &nbsp;&nbsp;case H5T\_ORDER\_BE:  
> &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_BE\n");  
> &nbsp;&nbsp;&nbsp;&nbsp;break;  
> &nbsp;&nbsp;case H5T\_ORDER\_VAX:  
> &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX\n");  
> &nbsp;&nbsp;&nbsp;&nbsp;break;  
> &nbsp;&nbsp;case H5T\_ORDER\_MIXED:  
> &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_MIXED\n");  
> &nbsp;&nbsp;&nbsp;&nbsp;break;  
> &nbsp;&nbsp;case H5T\_ORDER\_NONE:  
> &nbsp;&nbsp;&nbsp;&nbsp;printf("H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_NONE\n");  
> &nbsp;&nbsp;&nbsp;&nbsp;break;  
> &nbsp;&nbsp;default:  
> &nbsp;&nbsp;&nbsp;&nbsp;printf("here are dragons\n");  
> &nbsp;&nbsp;}  
> &nbsp;&nbsp;return 0;  
> }
> 
> on the same x86\_64 GNU/Linux machine I get
> 
> $ hdf5-1.8.11-gcc-4.7.0/my\_test # compiled with gcc 4.7.0  
> H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_LE
> 
> $ hdf5-1.8.11-gcc-4.8.0/my\_test # compiled with gcc 4.8.0  
> H5Tget\_order(H5T\_NATIVE\_LDOUBLE) = H5T\_ORDER\_VAX
> 
> So H5T\_NATIVE\_LDOUBLE is mis-detected. I tried to dig deeper and basically the fault must be in src/H5detect.c which is used to generate the definitions in src/H5Tinit.c  
> I could not figure out what H5detect.c does wrong (it is not very readable, given its extensive use of macros) but the compiler does emit a lot of warnings (see [https://gist.github.com/andreabedini/6419975](https://gist.github.com/andreabedini/6419975)).
> 
> I think this must be related to the failure of dt\_arith long double test observed recently.
> 
> Any suggestion on how to fix this ?
> 
> Best wishes,  
> Andrea
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>  
> \<hdf5\_uninitialized.patch\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> George N. White III \<aa056@chebucto.ns.ca\<[mailto:aa056@chebucto.ns.ca](mailto:aa056@chebucto.ns.ca)\>\>  
> Head of St. Margarets Bay, Nova Scotia
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>  
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>  
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>
> 
> --  
> Andrea Bedini \<[andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\<[mailto:andrea.bedini@gmail.com](mailto:andrea.bedini@gmail.com)\>\>
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> [Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\<[mailto:Hdf-forum@lists.hdfgroup.org](mailto:Hdf-forum@lists.hdfgroup.org)\>  
> [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> --  
> George N. White III \<aa056@chebucto.ns.ca\<[mailto:aa056@chebucto.ns.ca](mailto:aa056@chebucto.ns.ca)\>\>  
> Head of St. Margarets Bay, Nova Scotia
