Re: Problems with C floats

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

Your tests work. This is a different problem - many GTK routines return 2 or more values, as follows:

void                gtk_window_get_default_size         (GtkWindow *window, 
                                                         gint *width, 
                                                         gint *height); 
By allocating variables and passing them to the routine, they get filled in with the current values. This works fine as long as the vars are integers, pointers, or doubles, but when they are floats, I get an machine exception. I tried using safe.e, but can't see anything there to help. Perhaps this is related to the previous problem when passing floats to a c routine?

Not sure what you're doing as far as passing floats:

// irv.c 
// build with $ gcc -shared -fPIC -ldl irv.c -o irv.so 
#include <stdio.h> 
 
void pbr_float( float * pf ){ 
	*pf += 5.5f; 
} 

...and then...

-- irv.ex 
include std/dll.e 
include std/machine.e 
include std/convert.e 
 
constant 
	irv = open_dll( "./irv.so" ), 
	pbr_float  = define_c_proc( irv, "pbr_float", {C_POINTER} ) 
 
atom ptr = allocate( 4 ) 
poke( ptr, atom_to_float32( 1.5 ) ) 
 
c_proc( pbr_float, {ptr} ) 
 
? float32_to_atom( peek( ptr & 4 ) ) 

From that, I get:

$ eui irv 
7 

...which is correct.

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu