I need a cross-architectural way of ensuring that the float is 4 bytes (as in 32-bit windows). For example, in the structures that I create, I use __int32instead intto provide an integer value of 4 bytes in length.
__int32
int
How can I do this using float? I know that I can simply substitute a value with a type __int32; however, when casting on a float on 64-bit systems, I will not have problems?
I need a cross-architectural way to ensure that the float is 4 bytes
There is no analogue int32_tfor floating point values.
int32_t
- , , - .
#include <cassert> int main () { assert(sizeof(float) == 4); // If control reaches this line, then you've // ensured that float is 4 bytes. // rest of your program goes here }
, . IEEE-754 ( , , ) 4 .
IEEE-754
, , , C , . , CPU , , .
, static_assert sizeof(float) == 4; , , , . , ( .)
static_assert
sizeof(float) == 4