Callbacks with floats

new topic     » topic index » view thread      » older message » newer message

I believe this is fundamentally unsolveable, I just wanted to check.
(Specifically here, I am asking whether this is solvable in Open Euphoria.)
(And of course I don't mean never ever, just not with what we have right now.)

In C, the ACTION (redraw) callback on an IupCanvas is defined as:

int function redraw_cb(Ihandle *ih, float posx, float posy) 

which would naturally translate to the Phix code

function redraw_cb(Ihandle ih, atom posx, posy) 
constant cb_redraw = Icallback("redraw_cb") 

Note that Ihandle is effectively an atom, and Icallback() is just a call_back() wrapper.
The thing is that on 32bit ih is just an address whereas posx and posy are passed as
32-bit floats and could in theory be converted via float32_to_atom(int_to_bytes(posx/y)),
whereas on 64 bit, again ih is just an address (in rcx) but posx/y would be passed in
xmm1/2 and they would end up with whatever garbage happened to be in rdx/r9.
Unfortunately no extra type info is/can be specified in a call_back() call, and it is
that specific fact which makes this a fundamentally unsolveable problem.

Ultimately we cannot treat atom ih one way but atom posx another, cmiiw.

For sure, if I really really wanted to I could write a block of inline assembly and use
the address of that as the callback instead of a call_back() result, but, yuk.

Thankfully in the specific case this just cropped up in (IupCanvas ACTION callback)
there is a trivial workaround of fetching posx/y via IupGetDouble() instead.

Update: Again, just double!-checking, there isn't any way to sort this out via something like
define_c_func({},call_back(),{C_FLOAT/C_DOUBLE,...), is there?

new topic     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu