Re: free()'ing restrict'ed pointers
- From: s0suk3@xxxxxxxxx
- Date: Thu, 31 Jul 2008 09:53:56 -0700 (PDT)
On Jul 31, 10:46 am, "christian.bau"
<christian....@xxxxxxxxxxxxxxxxxx> wrote:
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.
Wow, seems like everybody's got a different idea about the subject.
But Ben Bacarisse said it's legal to *access* the object through
another pointer or a variable that holds the object (or array element,
etc), but not to *modify* it. Is that what you meant to? Or is it also
illegal to merely access it (through something other than the
restricted pointer or something that's not derived from it)?
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).
Reading q[0] is wrong? But q is the restricted pointer; why is it
wrong to access it or modify it?
Sebastian
.
- Follow-Ups:
- Re: free()'ing restrict'ed pointers
- From: Ben Bacarisse
- Re: free()'ing restrict'ed pointers
- From: santosh
- Re: free()'ing restrict'ed pointers
- References:
- free()'ing restrict'ed pointers
- From: s0suk3
- Re: free()'ing restrict'ed pointers
- From: christian.bau
- 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
|