문제

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.

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top