Re: free()'ing restrict'ed pointers



On Jul 31, 11:51 am, "christian.bau"
<christian....@xxxxxxxxxxxxxxxxxx> wrote:
On Jul 31, 3:37 pm, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:

   void *space = malloc(1);
   void *restrict rp = space;
   free(space); // are we modifying *rp? -- I don't know.

The "restrict" keyword allows to compiler to rearrange loads and
stores. So if you used int* instead of void* and an assignment to *rp
before the call to free (), the compiler could move the assignment
past the call to free () with bad consequences.

Two questions for clarification:

1. If we declare restricted pointer to an object, Is it true that,
essentially all the previously declared pointers cannot be used to
access the object until the restricted goes out of scope. And if we
do, the behavior is undefined

2. So in this case can I say. pointer 'space' is a not a pointer
derived from restricted pointer 'rp'.
And therefore cannot be used to access *rp. Hence cannot be used to
free it, free(space).

Thanks,
Ajay.
.



Relevant Pages

  • Re: restrict in plain English?
    ... it's impossible to swap a restrict pointer with another pointer, ... compiler might generate this code itself, ... The restrict qualifier only has meaning in terms of modifying an ...
    (comp.lang.c)
  • Re: restrict keyword from ISO C99?
    ... >>those memory blocks, where I the data in those locationcan be changed. ... Without restrict, it would not be ... > OK for the compiler to use parallel instructions, ... And in your example of a == b+1, you have performed pointer math on b ...
    (comp.lang.c)
  • Re: array subscript type cannot be `char`?
    ... "add any integer to pointer". ... Now, for through above, the compiler is probably forced to ... In particular, in assignment 6, the compiler is allowed to "know" ... might want to use 16-bit addition to address "small" arrays (with ...
    (comp.lang.c)
  • Re: CPtrList - Please Help me understand
    ... and the compiler would be happy. ... Now although bp has a pointer to an object of type B (which we know because we created ... compiler now happily does the assignment. ... Generally, casting has no effect on the representation of a value, other than instructing ...
    (microsoft.public.vc.mfc)
  • Re: Global restricted function pointer
    ... void; ... I _can_ declare a global restricted object pointer, ... the keyword restrict tells the compiler that two pointers ...
    (comp.lang.c)