type Mat4f* = array[0..15, float]
A proc that returns a matrix:
proc get_rot_mat*(camera:Camera) : Mat4f
And some code that calls:
var mat:Mat4f = cam.get_rot_mat()
The code generating at the call side is quite odd. It compiles in C and fails to compile in C++
C code:
mat4f708077 mat;
nimln(48, "main.nim");
glloadidentity_502807();
memset((void*)mat, 0, sizeof(mat));
nimln(59, "main.nim");
chckNil((void*)mat);
memset((void*)mat, 0, sizeof(mat));
getrotmat_711021((&cam_716039), mat);
C++ code:
mat4f708077 mat;
memset((void*)mat, 0, sizeof(mat));
nimln(59, "main.nim");
chckNil((void*)mat);
memset((void*)mat, 0, sizeof(mat));
getrotmat_711021((&cam_716039), mat);
It is interesting in both of these the redundant memetset and chckNil. I assume that is an optimization that might happen if I ran nim with the right flags?
C++ Compiler error:
/Users/amcharg/projects/voxamles/nimcache/main.cpp:286:2: error: no matching function for call to 'getrotmat_711021' getrotmat_711021((&cam_716039), mat); ^~~~~~~~~~~~~~~~ /Users/amcharg/projects/voxamles/nimcache/main.cpp:117:17: note: candidate function not viable: no known conversion from 'mat4f708077' (aka 'NF [16]') to 'mat4f708077 *' (aka 'NF (*)[16]') for 2nd argument; take the address of the argument with & N_NIMCALL(void, getrotmat_711021)(camera711013* camera, mat4f708077* Result);
I imagine most people pass these as refs or put them in an object? I prefer just having an array. I assume the compile error is a bug though.
Done: https://github.com/Araq/Nim/issues/2259
Yeah looking at the C code I am not sure how it works ether. The function takes a pointer to a matrix but only a matrix is being passed in.