can "if (ptr)" cause problems?
- From: "vl106" <vl106@xxxxxxxxxxx>
- Date: Fri, 17 Nov 2006 19:43:40 +0100
A static code analysis tool gave me a warning on
if (ptr && ptr->data) { ... }
I assumed the tool doesn't get the "short circuit behaviour" in
the if statement.
But a collegue said it may be the missing check ot ptr against
NULL.
What happens on an architecture where NULL isn't address
with all bits set to zero (e.g. 0xffff)? In this case my if-statement
will fail.
Does that mean the only portable way is "if (ptr != NULL)?.
if (ptr) and if (!ptr) would then be non-portable?
Thanks for your help.
.
- Follow-Ups:
- Re: can "if (ptr)" cause problems?
- From: Gordon Burditt
- Re: can "if (ptr)" cause problems?
- From: Ben Pfaff
- Re: can "if (ptr)" cause problems?
- From: dcorbit
- Re: can "if (ptr)" cause problems?
- From: Frederick Gotham
- Re: can "if (ptr)" cause problems?
- Prev by Date: Re: Array indexing
- Next by Date: Re: Object-oriented programming in standard ANSI C
- Previous by thread: C, signal, variable STOR and reentrancy
- Next by thread: Re: can "if (ptr)" cause problems?
- Index(es):