Re: free()'ing restrict'ed pointers



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.
--
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: free()ing restricted pointers
    ... is supposed to be accessed only through that pointer. ... If you have a pointer "int ... but not to *modify* it. ... restricted pointer or something that's not derived from it)? ...
    (comp.lang.c)
  • Re: free()ing restricted pointers
    ... 'restrict' is supposed to be accessed only through that pointer. ... If you have a pointer "int ... restricted pointer or something that's not derived from it)? ... Because you have lied to the compiler. ...
    (comp.lang.c)
  • Re: Using restricted pointers with newly allocated arrays/structures
    ... return (int) x; ... might return the same pointer. ... based on restricted pointer x, is used to access the object x(and ... yet the initialization of that object to 0.0 in ...
    (comp.std.c)
  • Re: Using restricted pointers with newly allocated arrays/structures
    ... return (int) x; ... based on restricted pointer x, is used to access the object x(and ... But the access in new_arrayuses the lvalue pwith address p. ...
    (comp.std.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. ... Greg Comeau / 4.3.10.1 with C++0xisms now in beta! ...
    (comp.lang.c)