I have recently learned about fixed-sized integer and am planning to use them in an old program I wrote years ago.
Is there any equivalent of fixed-sized int for float and/or double?
My plan is to use "native types" int,float,double
for the biggest part of the program and only specify fixed-size types when portability is a concern (like read/write with a binary file).
I use a binary file store data like: date yyyymmdd (so uint32
), flags [0,4] (so uint8
), string (null terminated string) and currencies (now it's double
).
Concerning portability, the program is "portable" is the sense that it can be compiled (or cross-compiled) and run on different platform. So far: linux, windows, android (natively, through a terminal emulator without GUI) and OpenBSD (strcat/strcpy only needs to be replaced by strlcat/strlcpy in 2 lines). I am concerned about what could happen to the stored float/double if I used the same binary data file between linux x86_64, android arm-something, windows 32 something, etc... I would like to have a way to enforce a unique size and representation of floating-point values in the binary file.