Re: Form k = i + j and test for overflow.



James Van Buskirk wrote:
(snip)

because C doesn't have an ASSOCIATED intrinsic, and C programmers
mostly aren't told to say:

if(ptr == SPECIAL_VALUE)

but instead:

if(ptr)

because the programmer is supposed to be able to tell whether or
not ptr points at something useful from whether the bit pattern of
ptr maps to true or false.

Note that for pointers, unlike other constants, the NULL pointer
is false and all others are true. While the usual NULL pointer
representation is all bits zero, the standard doesn't require
that. It does require that the constant zero cast to a pointer
be the NULL constant, though.

The problem for C programs lies in the fact that C boolean operators
spit out unique values for true and false results but any int in C
has a documented interpretation as true or false even though it may
not match one of the two bit patterns above.

With zero for false and non-zero for true. Now that you mention
it, I am not sure about negative zero....

-- glen

.



Relevant Pages

  • Re: How to know the memory pointed by a ptr is freed?
    ... > And what about the 37 copies made of that pointer after it was ... the value of "ptr" ... pattern stored in "ptr", or does it mean that we cannot under any ... that we gave that memory back to the system and any access to it ...
    (comp.lang.c)
  • Re: is NULL-checking redundant in accessor-functions?
    ... >> implementations of free don't, ... pattern apparently represents two different numbers? ... The answer lies in the *interpretation* of the bits. ... and the bits represent a pointer? ...
    (comp.lang.c)
  • Re: General method for dynamically allocating memory for a string
    ... Allocated memory is initialized to a machine-specific bit pattern ... a pointer accidentally. ... even on machines with 32-bit pointers): ...
    (comp.lang.c)
  • Re: How to know the memory pointed by a ptr is freed?
    ... >> Generally there will be some 'poison pattern' written to the pointer if it ... >> So the pattern might be of some clue. ... the pointer is typically left alone. ... >note that ptr is passed to the freefunction by value. ...
    (comp.lang.c)
  • Re: Typedef structs
    ... > to typedef a struct. ... Natural extension to opaque types - a commonly useful pattern is to ... easier both to make use of opaque (pointer) types and to explain some ...
    (comp.lang.c)