Pregunta
I've just begun to write my own memory manager, but to do that, I need some type of include file to create a f32
(float integer).
I have #include <cstdint>
in my program already, but I'm not sure what I would need for a F32
, or I32
for that matter.
Solución
AFAIK there's no standardized way to get fixed-width floating point types as of now - I think because, unlike integer types, float
and double
are more or less everywhere the same (32 bit float
, 64 bit double
, with separate types for "strange" FP types).
Still, if you want to be extra sure, you can do a static assert before creating your typedef:
#include <climits>
static_assert(sizeof(float)*CHAR_BIT==32, "float is not 32 bit on this architecture, fix the f32 typedef.");
typedef float f32;
In this way, on "sane" platforms this will work flawlessly, while on "strange" platforms it will fail to compile, giving you the chance to add a platform-specific typedef
.
As for I32, it's enough to include <cstdint>
and create your typedef:
#include <cstdint>
typedef std::int32_t i32;