struct s { int i; char * c; } *obj; obj = malloc(sizeof(struct s)); Say for example we have a struct as defined above (or any struct in general, i just wrote the above one for the sake of example).
Then, what is better when using the sizeof operator
sizeof(struct s) or sizeof(*obj) ?
I prefer the first one since it makes more sense to me (clearly tells us that we're allocating memory for an object of struct s)
Also, using the second one can introduce logical errors (like the usual 'forgetting to dereference the pointer')
Can the first one cause any problems? I haven't had problems with it yet but just wanted to know whether what i'm doing is proper or not.
If so, can you please provide an example of where it can fail?