[CCC DEV] REAL32 to FFI

Adam Sampson ats at offog.org
Tue Jun 29 08:04:41 BST 2010


Matt Jadud <jadudm at gmail.com> writes:

>   unsigned long int n = *((unsigned long int *) args[0]);
>   ... (float)n ...

You're getting bitten by C's lack of distinction between conversion and
retyping...

Saying "(float) n" is equivalent to "REAL32 ROUND n" in occam -- it's a
type conversion, so if you give it int 123 you'll get float 123.0.  To
do a retyping, you need to take a pointer to the int ("&n"), cast the
pointer into a pointer to a float ("(float *) &n"), then dereference it:
"float f = *((float *) &n)" is equivalent to "VAL REAL32 f RETYPES n:"
in occam.

If you can't persuade it to behave, I'd suggest comparing the bytecode
occ21 generates for INT32 and REAL32 versions of the FFI call to see
what it's actually doing...

-- 
Adam Sampson <ats at offog.org>                         <http://offog.org/>




More information about the developers mailing list