I usually make myself a struct and I allocate memory for the struct and sometimes for buffers inside the struct. Like so:
typedef struct A
{
char *buffer;
int size;
} A;
Then when I malloc for the struct I do this. (I learned not to cast the malloc return here on SO.)
X
A *a = malloc(sizeof(a));
a->buffer = malloc(10*sizeof(a->buffer));
What is the difference between X and Y this?
Y
A *a = malloc(sizeof(*a));
a->buffer = malloc(10*sizeof(a->buffer));
They seem to be doing the same thing.