Phix: float32 return value

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

Hello,

It's me again, even at the risk of annoying you all. After a year, I've started working on a wrapper for Raylib again. (Or rather, I've started programming again in general)

So far, I've been able to find a workaround/solution for everything. But now I'm stuck on something that is (in my opinion) relatively simple. More specifically, this:

constant xGetMouseWheelMove = define_c_func(ray,GetMouseWheelMove,{},C_FLOAT) 

Under Phix64bit, calling the function returns incorrect values, but under Phix32bit it works. My goal is 64bit.(also because my workarounds/solutions for passing structures and receiving them as return values only work with 64-bit).
And, to be perfectly honest, I don't feel like making my code even more unreadable than it already is with if 32bit then do this else do that.

To make it easier to investigate and visualize the whole thing, I have built a test system.

A DLL:

// File: test_ffi.c 
// compile with:- m32 for 32bit dll 
//gcc -shared -m64 -o test_ffi64.dll test_ffi.c   
//or 
//gcc -shared -m64 -s -o test_ffi64.dll test_ffi.c -Wl,--out-implib,libtest_ffi.a 
 
#include <windows.h> 
 
// Funktioniert in GCC/MinGW 
__attribute__((dllexport)) float GetTestFloat() { 
    return 123.456f; 
} 
 
__attribute__((dllexport)) float MultiplyFloats(float a, float b) { 
    return a * b; 
} 
 

And a test program:

sequence dll={"test_ffi64.dll","test_ffi32.dll"} 
atom result 
atom x=2.5,y=3.5 
atom lib=open_dll(dll) 
 
constant GetTestFloat= define_c_func(lib,"GetTestFloat",{},C_FLOAT) 
constant MultiplyFloats=define_c_func(lib,"MultiplyFloats",{C_FLOAT,C_FLOAT},C_FLOAT) 
 
 
printf(1,"%d Bit %s\n",{machine_bits(),"System"}) 
 
result=c_func(GetTestFloat,{}) 
printf(1,"%f should be 123.456\n",result) 
 
result=c_func(MultiplyFloats,{x,y}) 
printf(1,"%f should be %f\n",{result,x*y}) 
 
wait_key() 

As I said, it works with phix32 bit but not with phix64:

My working system is Windows11 64-bit Phix1.0.5

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

Search



Quick Links

User menu

Not signed in.

Misc Menu