float32_t / float64_t

Status
Not open for further replies.

kiplingw

Wise, Aged Ars Veteran
161
It's common place to see fixed width typedefs for integral types, like uint8_t, int64_t, etc., either in stdint.h or generated by the autotools.

What do others typically do for floating point types where they need to ensure that they are of a given width? e.g. Typically 32-bits for single precision and 64-bits for double precision. This can be needed when one needs to send binary data out to disk or over the network containing floats where endianness at least is known, but width is not, and it may be read at the other end by a different machine. :confused:
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
It used to be a lot worse. int, depending on your compiler/system could be 16-bit or 32-bit, for instance. And yeah, back then we used to be very specific in any data export/import routines (files and network) so there was no ambiguity when anyone looked at the code... from the most experienced developers to the least experienced developers in our group. We also had to make sure endianness was correct all the time. One product we had actually had client and server software and any combination of big/little endian could be used for either (potentially quite a few numbers of either) at any particular site.
 

kiplingw

Wise, Aged Ars Veteran
161
Sounds like it use to be a real mess. It looks like getting fixed width integral types is no problem through stdint.h at least and endianness you can also get the autotools to figure out for you at configure time. It's the width and encoding of floats that is the problem. Although, it looks like numeric_limits<float>::is_iec559() at least tells me whether it is properly encoded IEC-559 / IEEE-754 format. I guess that information combined with compile-time #ifdef sizeof(float) == 4 and for double might be what I need to do.
 

stickboy

Ars Tribunus Angusticlavius
6,218
Subscriptor
kiplingw":rs6xc9ci said:
#ifdef sizeof(float) == 4
  1. #ifdef tests whether a macro is defined, not whether an expression is true. You mean #if.
  2. The preprocessor knows nothing of sizeof or C types.
It is possible to make compile-time assertions (for example: http://www.jaggersoft.com/pubs/CVu11_3.html ), just not for what you want here with the preprocessor.
 
Status
Not open for further replies.