This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: restrict keyword [was: expalin this syntax pls]
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Joe Buck <jbuck at synopsys dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Sat, 19 Oct 2002 00:20:16 +0100 (BST)
- Subject: Re: restrict keyword [was: expalin this syntax pls]
On Fri, 18 Oct 2002, Joe Buck wrote:
> Consider rtest.c
> -----------------------------------------------
> void f(const int* restrict pci, int* restrict pi);
>
> int main()
> {
> int n;
> f(&n, &n);
> }
> -----------------------------------------------
>
> This is not a legal program: f's arguments are restricted pointers,
> meaning that we promise the compiler that there is some data that
> can be accessed only through pci, and other data that can be accessed
> only through pi, yet we pass the same value to both pointers.
It's a perfectly legal program if f doesn't actually write through pi
(missing an optional const). Remember that the definition of restrict was
changed substantially between the last public draft and the FDIS (at the
instigation of the UK) to a model where there can be readonly access
through multiple restricted pointers unless the data is written to.
--
Joseph S. Myers
jsm28@cam.ac.uk