In C, it is a common idiom to zero out the memory for a struct
using memset
:
struct x myStruct;
memset(&myStruct, 0, sizeof(myStruct));
Technically speaking, I don't believe that this is portable because it assumes that the NULL
pointer on a machine is represented by the integer value 0, but it's used widely because on most machines this is the case.
If you move from C to C++, be careful not to use this technique on every object. C++ only makes this legal on objects with no member functions and no inheritance.