Thursday, 15 September 2011

c - Check if pointer is null when not initialized -



c - Check if pointer is null when not initialized -

this question has reply here:

why aren't pointers initialized null default? 15 answers

is safe assume if statement work if variable uninitialized? assumption yes, have been told random bits of garbage in variable not mean check if null work.

void afunction () { char* somestr; if (somestr) { // } }

is safe assume if statement work if variable uninitialized?

no. reading uninitialized storage invokes undefined behavior. can't create safe assumptions code.

don't this!

c

No comments:

Post a Comment