Re: restrict keyword from ISO C99?
From: tweak (xbwaichunasx_at_cox.net)
Date: 06/19/04
- Next message: Foobarius Frobinium: "Re: Pointer Guide"
- Previous message: Tim Prince: "Re: restrict keyword from ISO C99?"
- In reply to: E. Robert Tisdale: "Re: restrict keyword from ISO C99?"
- Next in thread: Tim Prince: "Re: restrict keyword from ISO C99?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 18 Jun 2004 19:20:03 -0700
E. Robert Tisdale wrote:
> tweak wrote:
>
>> Can someone give me a short example as how to best use this keyword in
>> your code?
>
>
> #include <string.h>
>
> void *memcpy(void *restrict dest,
> const void *restrict src, size_t n);
>
>> This is my understanding: by definition restrict sounds like
>> it is suppose to restrict access to memory location(s) pointed to,
>> so that only one declared pointer
>> can store that address and access the data in those memory blocks,
>> where I the data in those location(s) can be changed.
>>
>> Is that a correct understanding?
>
>
> Probably not.
>
> The restrict keyword is a promise by the programmer to the compiler
> that the destination [dest] array is *not* an alias
> for any part of the source [src] array -- they don't overlap.
> But there is, in general, no way for the compiler to determine
> whether they are actually aliases or not so the programmer can lie.
> The behavior is *undefined*
> if copying takes place between objects that overlap.
For clarity:
aliases == variables?
objects == memory locations (&) ?
So if an array with four elements (e.g. char name[4]) occupied 0x01
through 0x05, where 0x05 is '\0', and another array with four elements
(e.g. char fullname[4]) occupied 0x04 through 0x08, where 0x08 is '\0',
then overlap would occur. And the restrict keyword specifies that the
programmer promises to keep the overlapping from occurring, but the
compiler cannot confirm? Is this a better understanding?
Thanks,
Brian
- Next message: Foobarius Frobinium: "Re: Pointer Guide"
- Previous message: Tim Prince: "Re: restrict keyword from ISO C99?"
- In reply to: E. Robert Tisdale: "Re: restrict keyword from ISO C99?"
- Next in thread: Tim Prince: "Re: restrict keyword from ISO C99?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|