Passing Floats by Value

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

Hi,

I have a routine in a DLL defined as such:

 EXPORT VOID CALLBACK myFunc( float f0, float f1 )
  {
  printf("%f %f\n", f0, f1 );
  }

I "link" to it from Euphoria like so ('m_DLL' is valid):

 constant m_myFunc = define_c_proc( m_DLL, "_myFunc@8", {C_FLOAT, C_FLOAT})

when I call the routine:

 c_proc( m_myFunc, {1.0, 1.0} )

the following prints out:

 0.000000 0.000000


If I change *JUST* 'C_FLOAT' to 'C_DOUBLE' like so:

 constant m_myFunc = define_c_proc( m_DLL, "_myFunc@8", {C_DOUBLE,C_DOUBLE})

the output becomes:

 0.000000 1.875000


Lastly, if I change *ALL* 'float' to 'double' and *ALL* 'C_FLOAT' 'to
C_DOUBLE' like so:

 EXPORT VOID CALLBACK myFunc( double d0, double d1 )
  {
  printf("%f %f\n", d0, d1 );
  }

 constant m_myFunc = define_c_proc( m_DLL, "_myFunc@16",{C_DOUBLE,C_DOUBLE})

the output becomes, as expected:

 1.000000 1.000000


Now, I'm sure the above has to do with the fact that an ATOM is 8-bytes,
and it *APPEARS* Euphoria is passing 8-bytes per parameter to a routine
that is expecting 4-bytes per parameter.

So the question is:

How do I pass a 4-byte floating point value from Euphoria to a C routine?

(The above code is just a mock up to demonstate my dilemma, in reality the
DLL routine I wish to pass data to is pre-compiled and I don't have access
to the source code, so if I can't figure out how to pass a float, I can't
use the DLL.)

Thanks In Advance,
David

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

Search



Quick Links

User menu

Not signed in.

Misc Menu