Re: restrict keyword from ISO C99?

From: tweak (xbwaichunasx_at_cox.net)
Date: 06/19/04


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



Relevant Pages

  • Re: Symbols for range/iteration/slicing
    ... loop as keyword. ... I would suggest the keyword 'range' ... words I take away from the programmer. ... Do you want C like statements with or without brace, ...
    (comp.lang.misc)
  • Re: C# or VB.NET?
    ... As with so many things in the development world, it comes down to good coding guidelines that you and your team must agree to follow. ... Just because I want the compiler to find the most errors/situations it can. ... I didn't like this keyword in VB6. ... I find Option Explicit/Strict being optional ... ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Opinions about a book
    ... restricted pointers (restrict keyword). ... variable-length Arrays ... Or perhaps the documentation is out of sync with the compiler. ...
    (comp.lang.c)
  • Re: Register keyword and "as if" rule...
    ... its way to take a full 10 minutes every time a "register" declared ... Then my compiler is still C compliant, ... keyword if they want their code to run smoothly on all implementations: ... Optimization hints in general are not nearly so important as they were ...
    (comp.lang.c)
  • Re: C# or VB.NET?
    ... Everybody knows to turn on Explicit/Strict options. ... I still get arguments why some developers don't want to use it that way. ... I didn't like this keyword in VB6. ... As it been for years C# compiler is less guessing/forgiven than VB.NET ...
    (microsoft.public.dotnet.framework.aspnet)