Re: Passing floats/doubles to C

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

In various posts Todd Riggins writes:

>  DllExport int SET_MATERIALS(MATERIAL material)

>  DllExport int SET_MATERIALS(LPMATERIAL material)

>  DllExport int SET_MATERIALS(double material[17])

Be careful how you declare the C function.
C does not support passing arrays by value, and Euphoria
does not support passing C structures by value, only by
pointer. That makes the 1st declaration above
unworkable, and I think the 3rd one should be:
     double *material
if you want to pass a pointer to an array of doubles.
The middle one is ok too if the parameter coming from
Euphoria should be treated as a pointer to a C structure.

If you declare the C parameter incorrectly it could possibly
cause the strange values that are printed by the C program,
since the data on the stack will not be what C is expecting.

Also, I recommend that you pass a variety of interesting
numbers, not just 1.0.  It will make it easier to see
what has gone wrong.

I don't see any fundamental reason why your code can't
be made to work, but I know that it gets very tricky at this level.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu