[SOLVED] Declaration of platform dependent types

Currently I started to study Kha and saw the file FastFloat.hx which declares 32 floating point number for different platforms:

#if cpp
typedef FastFloat = cpp.Float32;
#elseif hl
typedef FastFloat = hl.F32;
#elseif java
typedef FastFloat = Single;
#else
typedef FastFloat = Float;
#end

I used abstract for this:

abstract Float32(#if hl hl.F32 #elseif cpp cpp.Float32 #else Float #end) from Float to Float {}

So the question is, is there any real difference and does abstract affect performance.

There’s no real difference. The underlying type on an abstract is what’s generated wherever the abstract is used.

The performance cost would be is if you’re using a constructor for the abstract? Since then youd be calling a function whenever it’s constructed.

2 Likes