Originally Posted by
MutantJohn
Yay, I wrote good code for once!!!
I tend to disagree.
You typedef a pointer which makes your code harder to read. I would suggest something like:
Code:
typedef struct node
{
int type;
} node_t;
...
node_t ***omfg = malloc(gl * sizeof(*omfg));
which makes it clear that "omfg" is a pointer to pointer to pointer to node_t. (Actually I don't see a reason for the typedef at all instead of just using "struct xxx" as the type.)
Notice also how I use "omfg" with the sizeof operator. The basic idea is to always dereference the variable you are allocating memory for:
Code:
T *var_name;
var_name = malloc(sizeof(*var_name));
Thus if you ever have to change the type of your pointer (T) you can do it at one single line.
The same works for your other two malloc() calls:
Code:
omfg[i] = malloc(gl * sizeof(*omfg[i]));
omfg[i][j] = malloc(gl * sizeof(*omfg[i][j]);
Bye, Andreas