Re: free()'ing restrict'ed pointers
- From: "christian.bau" <christian.bau@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 08:46:55 -0700 (PDT)
On Jul 31, 2:40 pm, s0s...@xxxxxxxxx wrote:
Hi,
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? Does free() try to access what
in points to in some way?
You are quoting incorrectly what "restrict" means: The data pointed to
may be accessed through the restrict pointer itself, or through a
pointer derived from that pointer. If you have a pointer "int
*restrict p" and call free (p), then the argument to free is derived
from p and is allowed to access the data as much as it likes.
Now what is wrong is the following:
int* p = malloc (100);
int* restrict q = p;
p [0] = 1;
free (q);
(the call free (q) is just as wrong as an assignment q [0] = 2 or just
reading q [0] would be).
.
- Follow-Ups:
- Re: free()'ing restrict'ed pointers
- From: s0suk3
- Re: free()'ing restrict'ed pointers
- References:
- free()'ing restrict'ed pointers
- From: s0suk3
- free()'ing restrict'ed pointers
- Prev by Date: Re: Procyon Library for Atmel AVR MCU - I²C problems
- Next by Date: Re: free()'ing restrict'ed pointers
- Previous by thread: Re: free()'ing restrict'ed pointers
- Next by thread: Re: free()'ing restrict'ed pointers
- Index(es):
Relevant Pages
|