C
copx
This is the first I have to allocate a 3D array somehow my imagination
isn't sufficient to clearly visualize the process so I've written the code
based on assumptions without actually understanding it.
It SEEMS to work but especially as far as mem. allocation is concerned that
doesn't mean a thing.
Could you please look at my code and tell me if it's correct or not?
int *** World;
void world_new(int x, int y, int z)
{
int i, j;
World = malloc(x * sizeof *World);
for (i = 0; i < x; i++) {
World = malloc(y * sizeof **World);
for (j = 0; j < y; j++) {
World[j] = malloc(z * sizeof ***World);
}
}
}
(No need to point out the lack of malloc error checks. My project uses a
warper around malloc which handles those.)
copx
isn't sufficient to clearly visualize the process so I've written the code
based on assumptions without actually understanding it.
It SEEMS to work but especially as far as mem. allocation is concerned that
doesn't mean a thing.
Could you please look at my code and tell me if it's correct or not?
int *** World;
void world_new(int x, int y, int z)
{
int i, j;
World = malloc(x * sizeof *World);
for (i = 0; i < x; i++) {
World = malloc(y * sizeof **World);
for (j = 0; j < y; j++) {
World[j] = malloc(z * sizeof ***World);
}
}
}
(No need to point out the lack of malloc error checks. My project uses a
warper around malloc which handles those.)
copx