T
Thes
Hi all,
I have a 2d float array to which I have declared a pointer thus:
float Matrix[4][3] = {/* snipped initialisation */ };
float (*StoredMatrix)[4][3];
So as to create a copy in a program "registry" of my own devising.
I copy the Marix array as follows:
StoredMatrix = malloc(sizeof Matrix);
if(!StoredMatrix)
{
memcpy((void*)StoredMatrix, (void*)Matrix, sizeof Matrix);
}
else
{ /* take action */ }
My question is whether this is legal, and if so whether it is dangerous?
So far, the copied version dereferences OK using the [] operators - eg
using *StoredMatrix[2][1] etc. I'm not finding K&R helpful on the subject.
Any advice appreciated.
TheS
I have a 2d float array to which I have declared a pointer thus:
float Matrix[4][3] = {/* snipped initialisation */ };
float (*StoredMatrix)[4][3];
So as to create a copy in a program "registry" of my own devising.
I copy the Marix array as follows:
StoredMatrix = malloc(sizeof Matrix);
if(!StoredMatrix)
{
memcpy((void*)StoredMatrix, (void*)Matrix, sizeof Matrix);
}
else
{ /* take action */ }
My question is whether this is legal, and if so whether it is dangerous?
So far, the copied version dereferences OK using the [] operators - eg
using *StoredMatrix[2][1] etc. I'm not finding K&R helpful on the subject.
Any advice appreciated.
TheS