3 ms·
On the other hand, if it's available, Valgrind will do a better job of catching uninitialized memory use if you use malloc instead of calloc. (IMO, explicit in
by pcwalton 13y ago
On the other hand, if it's available, Valgrind will do a better job of catching uninitialized memory use if you use malloc instead of calloc.
(IMO, explicit initialization is better than just zeroing stuff out, because there's no guarantee that zeroed memory is valid. Especially when pointers are involved—dereferencing a null pointer in C is undefined behavior, so compilers are free to wreak havoc on any code that it can prove attempts to do that...)
- thepumpkin1979 13y agoThat's true. I usually initialize the struct in the stack and then assign it to the pointer, then pass the pointer around.