Re: checking if pointer is NULL allowed?
Ben Pfaff wrote:
It is common practice in many shops I've worked at to have a function or
macro used in debugging routines that can take a pointer and return the
pointer or "null", depending on if the pointer is valid to dereference
or not.
Ben Pfaff wrote:
Alef.Veld@gmail .com writes:
>
>
Are you confusing dereferencing an invalid pointer with passing a
null pointer to printf in place of a pointer argument? Both are
undefined behavior. The former is usually difficult or expensive
for an implementation to detect, whereas the latter is handled
gracefully by better-quality C libraries (which often do print
"null" or "(null)").
>
>Well, if it is not pointing to anything anyway, couldn't my compiler
>just printf out "null". And i swear i thought i have seen this.
>just printf out "null". And i swear i thought i have seen this.
Are you confusing dereferencing an invalid pointer with passing a
null pointer to printf in place of a pointer argument? Both are
undefined behavior. The former is usually difficult or expensive
for an implementation to detect, whereas the latter is handled
gracefully by better-quality C libraries (which often do print
"null" or "(null)").
macro used in debugging routines that can take a pointer and return the
pointer or "null", depending on if the pointer is valid to dereference
or not.
Comment