Re: free()'ing restrict'ed pointers
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Thu, 31 Jul 2008 15:37:30 +0100
s0suk3@xxxxxxxxx writes:
A object to which there is a pointer that has been declared 'restrict'
is supposed to be accessed only through that pointer.
Hmmm.... A better (and I am sure this is not the last word on the
subject) is that objects that have a restrict qualified pointer to
them are only /modified/ via that pointer while it exists[1]. You can
access the value via other means, it is modifications that must be via
the pointer.
So is it safe to call free() with a restricted pointer?
Usually, yes.
Does free() try to access what in points to in some way?
I does not matter since it would be allowed to, at least by the
restrict keyword. It is possible that UB results at the exact moment
free is called in this daft code:
void *space = malloc(1);
void *restrict rp = space;
free(space); // are we modifying *rp? -- I don't know.
but that is very much an academic argument. This is fine:
void *restrict rp = malloc(1);
free(rp);
[1] This last bit plays fast a loose with the very precise definition
of the time during which the restrict restrictions apply, but it is
not a bad approximation to the truth.
--
Ben.
.
- Follow-Ups:
- Re: free()'ing restrict'ed pointers
- From: christian.bau
- Re: free()'ing restrict'ed pointers
- References:
- free()'ing restrict'ed pointers
- From: s0suk3
- free()'ing restrict'ed pointers
- Prev by Date: Re: Weird malloc behaviour
- Next by Date: Re: Procyon Library for Atmel AVR MCU - I²C problems
- Previous by thread: Re: free()'ing restrict'ed pointers
- Next by thread: Re: free()'ing restrict'ed pointers
- Index(es):
Relevant Pages
|