: memset has the signature
:
:
void *memset(void *s, int c, size_t n);
:
:
: Anyone know what happens if you call it this way??
:
:
memset(NULL, <some number>, <some size>);
:
: I'm wondering if sees the NULL and then knows not to do anything (like a no-op) or if it will crash/something-else because it's trying to access the NULL... Or is the whole situation just undefined...???
:
: I can't find any documentation or examples that tells what happens in this case... Of course I could write a quick test program, but it would be platform-specific, and I want to know if there is a standard definition of this behaviour... My point is, I have a lot of code to zero out a structure tree with lots of pointers, and I'm hoping there's some way that it will be smart and do a no-op... Otherwise, everywhere I could potentially have a NULL pointer, I'm going to have to go add
:
:
if (ptr)
: memset(ptr, 0, <whatever size of the struct it's pointing to> );
:
: And I really don't want to have to do that...
:
: TIA
:
You should always initialize pointers, and always check them before you use them. Get yourself in the habit of doing that and save yourself lots of time later.
To understand recursive, first you need to understand recursive