RE: How can I pass an atom to a C function as C float or double

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

>From: Al Getz <Xaxo at aol.com>
>Subject: RE: How can I pass an atom to a C function as C float or double
>
>
>euman at bellsouth.net wrote:
> >
> >
> > On 12 Sep 2003 at 23:27, myotis at xnet.ro wrote:
> >
> > > Please tell me how can I pass an atom as a C float to a C
> > > function from a dll. The same question is for a C double ...
> > >
> > > Example of the C function in DLL :
> > >
> > > float MyFunction( float parameter1, double parameter2 );
> > >
> > > I have tried all the posible combinations ( C_FLOAT in define the C
> > > function, atom_to_float32 when I pass the arguments ... nothing work )
> > >
> > > Please write to me a little piece of euphoria code that call this
> > > function in Euphoria. Also tell me the calling convention you are 
>write
> > > for ...
> > > I can change this in my DLL as I want.
> > >
> > > Also, please tell me if the version of euphoria you are
> > > writeing for the example, matter for some reason.
> > >
> > > Thank you !
> >
> > Can you try this:
> >
> > integer junk
> > junk = allocate(5)
> > poke(junk, atom_to_float32(x))
> > poke4(junk+1, atom_to_float64(y))
> >

What is this??
Firstly, junk is a memory address, so it should be an atom.
Secondly, atom_to_float32() returns 4 bytes, not 1, so the subsequent poke 
will overwrite it.
Thirdly, atom_to_float64() returns 8 bytes, times 4, making 32, which 
wouldn't fit in the allocated 5.
Fourthly, you don't even need pointers.

> > then pass your params the pointer to "junk"
> >
> > f = Myfunction(peek(junk),peek4(junk+1))
> >
> >
>Hello there,
>
>Good idea Wayne, i was thinking he wanted to pass by value,
>but did you mean to say:
>     f = Myfunction(junk,junk+1)
>or just
>     f = Myfunction(junk)
>instead?
>
>Take care for now,
>Al

Uh, for pass by value, what are you using pointers for? Simply define the 
function with C_FLOAT or C_DOUBLE and use the atom as the parameter.

--for: float MyFunction( float parameter1, double parameter2 );

constant
xMyFunction = define_c_func(dll, "MyFunction", {C_FLOAT, C_DOUBLE}, C_FLOAT)

global function MyFunction(atom param1, atom param2)
    return c_func(xMyFunction, {param1, param2})
end function

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

Search



Quick Links

User menu

Not signed in.

Misc Menu