Hi guys,
I've got a C wrapper procedure:
type
Body* = ptr object
BB* = object
l*: Float
b*: Float
r*: Float
t*: Float
Float* = cdouble
proc newBoxShape*(body: Body; box: BB; radius: Float): PolyShape {.cdecl, importc: "cpBoxShapeNew2".}
The C code that the above declaration wraps is this:
typedef double cpFloat;
typedef struct cpBB{
cpFloat l, b, r ,t;
} cpBB;
cpShape *cpBoxShapeNew2(cpBody *body, cpBB box, cpFloat radius)
{
printf("%f", radius) // <- INSERTED BY ME TO SEE WHAT'S GOING ON
return (cpShape *)cpBoxShapeInit2(cpPolyShapeAlloc(), body, box, radius);
}
When calling the newBoxShape proc in Nim like this:
var shape = newBoxShape(
body=body,
box=newBB(-30.0, -30.0, 50.0, 50.0),
radius=10.0
)
the value of radius in the C 'printf' function call when compiled with MinGW64-GCC 5.2.0 is 0.0, but it should be 10.0! The body and the box parameters are correct, though.
This seems to be a Windows specific problem, as it was tested on Linux and it worked. I've tried this on Windows Vista 64-bit and Windows XP 32-bit with the same result. Nim compiler in both cases is:
Compiler Version 0.13.1 (2016-05-29) [Windows: i386]
GCC: MinGW-64 5.2.0 (x86)
Also tested it with the MSVC 2010 compiler (x86), but then the 'printf' function call is -30.0 ???
Any Ideas?
Use the .bycopy pragma for the BB object.
http://nim-lang.org/docs/manual.html#foreign-function-interface-bycopy-pragma