Re: does a program work in all cases?



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
.



Relevant Pages

  • Re: Need help with REDEFINES (I think)....
    ... preclude the compiler optimizing it. ... (a compiler generated subroutine) ... generated subroutine) because it uses a simple compare (or series of ... would be fairly consistent across platforms, but even if I'm wrong and there ...
    (comp.lang.cobol)
  • Re: Divisibility of a java.math.BigInteger object
    ... and possibly faster to just extract the two least significant ... digits and compare them with »00«. ... To access the internal representation of a BigInteger use ... represenataion in decimal digits, though I suspect that will be too ...
    (comp.lang.java.programmer)
  • Re: does a program work in all cases?
    ... printf("Failed to allocate memory\n"); ... necessarily true on all platforms. ... So!NULL will be true on all conforming ...
    (comp.lang.c)
  • Re: Dates are Evil! HELP!
    ... ToShortDateString returns a *string*. ... compare "real" dates and not strings: ... given date has always the same internal representation. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Manchester Piccadily Through Platforms
    ... through platforms 13/14 (alightly more in rush hours). ... compare that to today - 8 trains an hour in each direction ...
    (uk.railway)