Re:Memory management in C programs
by thepumpkin1979 on Monday March 17, 2014 @03:26AM
(#7413629)
That's true. I usually initialize the struct in the stack and then assign it to the pointer, then pass the pointer around.
(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...)