I need a cross-architecture way to ensure that a float will be 4 bytes (as is on 32-bit windows). For instance, in the structs I'm creating, I'm using __int32
instead of int
to ensure an integer value that is 4 bytes long.
How could I do this with a float? I know that I can just substitute the value with an __int32
type; however, when casting to a float on 64-bit systems, won't I have issues?
I need a cross-architecture way to ensure that a float will be 4 bytes
There is no analog to int32_t
for floating-point values.
The only cross-platform way to achieve what you want is to test for it with either runtime or static asserts.
#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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With