Hello,

I wanted to ask.
If I define typedef float mymat3[3];

and then I have a function:

void myfunc(float *One_mat_, .... 

and inside function I do:

mymat3 * One_mat=(mymat3 *)One_mat_;

while(i<numPoints) { 
        One_mat[i][0] = (One_mat_[++c1]);

Does this mean , that I am copying One_mat_ (which I am casting it as a mymat3 ) to One_mat which is defined as a mymat3 matrix ?

And why as an argument I have float *One_mat_ and inside function I do: (mymat3 *)One_mat_ and not (float *)One_mat_ ?

Could I have inside argument the void myfunc(mymat3 * One_mat_, .... instead of void myfunc(float *One_mat_, .... ?

Thanks!

Does this mean , that I am copying One_mat_ (which I am casting it as a mymat3* ) to One_mat which is defined as a mymat3 matrix ?

No, you are only making a copy of the pointer. The cast from float* to mymat3* causes the pointer One_mat_ to be copied into a pointer of a different type, the One_mat pointer. These are pointers, i.e., only an address value, copying them does not copy the memory at the address they point to.

And why as an argument I have float *One_mat_ and inside function I do: (mymat3 *)One_mat_ and not (float *)One_mat_ ?

You are asking us why you did this? I don't know, you are the one who wrote that code (presumably), you should know why you wrote it that way, or at least, what you expected it would do. I am not a mind-reader.

All I know is that it is a very questionable piece of code. It is valid, but very fragile and certainly not recommended.

Could I have inside argument the void myfunc(mymat3 * One_mat_, .... instead of void myfunc(float *One_mat_, .... ?

Yes, and you probably should. Or better yet, use void myfunc(mymat3& One_mat_, ...., i.e., pass the static array by reference, this way you will avoid the error-prone double-dereferencing syntax.

Ok,thanks for your answer.

(The code wasn't mine,I just used 'I')

This question has already been answered. Start a new discussion instead.