effect of free()

Norman Diamond diamond at csl.sony.co.jp
Wed Sep 13 13:49:43 AEST 1989


In article <247 at bbxeng.UUCP> scott at bbxeng.UUCP (Scott-Engineering) writes:
>>In other words - you cannot even *test* a pointer unless you are *sure*
>>there is a valid address in it.  I don't think so.

In article <10985 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:

>There is no way a strictly conforming C program can create an invalid
>pointer value, apart from free()ing a valid one that it got from malloc()
>or realloc().  The moment an improper pointer value is created via
>arithmetic operations, the program has violated the guarantees of the
>Standard, and the implementation would be free to trap immediately.

Another way to create a pointer that does not point to an object is to
assign a NULL constant to it.

A pointer variable containing a valid pointer value may be compared to
a NULL constant.

Scott-Engineering's posting implies these questions (among others):
(1) if a pointer variable contains a NULL value, then may that pointer
     be compared to a NULL constant?
(2) if a pointer variable contains a NULL value, then may that pointer
     be compared to a valid pointer value?

Scott-Engineering's reading of the standard implied negative answers,
which he finds hard to believe.  (I still can't get a copy of the
proposed standard and cannot form an opinion.)  Mr. Gwyn, perhaps you
could please post a better answer.

--
-- 
Norman Diamond, Sony Corporation (diamond at ws.sony.junet)
  The above opinions are inherited by your machine's init process (pid 1),
  after being disowned and orphaned.  However, if you see this at Waterloo or
  Anterior, then their administrators must have approved of these opinions.



More information about the Comp.lang.c mailing list