Re: does a program work in all cases?
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Mon, 18 Dec 2006 00:56:31 +0000 (UTC)
In article <1166398904.681493.255850@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Spiros Bousbouras <spibou@xxxxxxxxx> wrote:
Ben C wrote:
On 2006-12-17, Sheldon <shejo284@xxxxxxxxx> wrote:
}
if (!(arr)) {
printf("Failed to allocate memory\n");
...even though you do check this one, but only after using it, which is
a bit late.
You also should really go if (arr != NULL) because !NULL is not
necessarily true on all platforms.
NULL is 0 or (void *) 0 and paragraph 5 of 6.5.3.3
of N1124 says that applying the ! operator to a zero
value gives 1. So !NULL will be true on all conforming
platforms.
No, NULL is *not* necessarily 0 or (void *)0 : it can have
any internal representation the compiler desires. What the
standard promises is that it will *compare* equal to 0.
Meanwhile !p is just shorthand for p!=0 and as NULL must compare
equal to 0, p!=0 must be false if p is NULL.
It's the same end result, but the internal details are
different than you are implying.
--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell
.
- Follow-Ups:
- Re: does a program work in all cases?
- From: Keith Thompson
- Re: does a program work in all cases?
- From: malc
- Re: does a program work in all cases?
- References:
- does a program work in all cases?
- From: Sheldon
- Re: does a program work in all cases?
- From: Ben C
- Re: does a program work in all cases?
- From: Spiros Bousbouras
- does a program work in all cases?
- Prev by Date: Re: Dynamic C to C Data Transfer
- Next by Date: Re: How does C handle issues arising out of Endianness?
- Previous by thread: Re: does a program work in all cases?
- Next by thread: Re: does a program work in all cases?
- Index(es):
Relevant Pages
|