Re: free()'ing restrict'ed pointers



In article <g6t1ir$6t7$1@xxxxxxxxxxxxxxxx>,
Greg Comeau <comeau@xxxxxxxxxxxxxxxxxxx> wrote:
In article <g6sg41$tlr$1@xxxxxxxxxxxxxxxxxxxxxxxxx>,
santosh <santosh.k83@xxxxxxxxx> wrote:
s0suk3@xxxxxxxxx wrote:
A object to which there is a pointer that has been declared 'restrict'
is supposed to be accessed only through that pointer. So is it safe to
call free() with a restricted pointer?

Yes.

Does free() try to access what
in points to in some way?

It most certainly accesses it's argument, but whether it accesses the
storage pointed to is not specified. In any case after calling free the
pointer object is left in an indeterminate state, and the storage
pointed at is no longer available. So it shouldn't matter to you
whether free accesses the storage or not.

It's worth pointing out that the restrict'ed point was originally
re/c/m/alloc()d and "handed over" to the restricted pointer.
But that of course does not make the memory restricted,
just through the restricted pointer it is treated as such.
So if you will, it can be "renomalized" back to being non-restricted
by being rehanded over again, in this case to free.

Um, ignore this response....
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
.



Relevant Pages

  • Re: Difference between function pointers
    ... with an operand of pointer to function type. ... Greg Comeau / 4.3.10.1 with C++0xisms now in beta! ...
    (comp.lang.c)
  • Re: Segmentation fault error
    ... Greg Comeau wrote: ... may actually be a null pointer on the above system (which means ing ... When argc is not greater than zero it must be zero and argvwill ... of functions by simply giving a misleading string or nothing at all as ...
    (comp.lang.c)
  • Re: free()ing restricted pointers
    ... is supposed to be accessed only through that pointer. ... storage pointed to is not specified. ... just through the restricted pointer it is treated as such. ... Comeau C/C++ with Dinkumware's Libraries... ...
    (comp.lang.c)
  • Re: classes in functions
    ... "Greg Comeau" wrote in message ... > Just think of the internal pointer implementation of references ... "drill down into" using the dot operator and the object identifier (direct ... I then just say a reference, used in function formal parameters is a second ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Threading problem
    ... Your analysis about the storage being freed is the ... but if this is a pointer to free storage on the ... now you can set it up so that it disables all controls (e.g., ... LRESULT CMyForm::OnThreadDone ...
    (microsoft.public.vc.mfc)