__restrict__ vs __restrict ?
Ruslan Ermilov
ru at FreeBSD.org
Fri Jan 16 17:57:49 PST 2004
On Fri, Jan 16, 2004 at 05:23:01PM -0800, Tim Kientzle wrote:
> I've been enabling a LOT of gcc warnings recently
> in the process of linting some code I'm writing.
> In the process, I stumbled across the following
> curiosity:
>
> > cat test.c
> #include <stdio.h>
> > gcc -std=c99 -ansi test.c
> In file included from test.c:1:
> /usr/include/stdio.h:220: conflicting types for `restrict'
> /usr/include/stdio.h:220: previous declaration of `restrict'
> /usr/include/stdio.h:221: conflicting types for `restrict'
> /usr/include/stdio.h:221: previous declaration of `restrict'
> /usr/include/stdio.h:222: redefinition of `restrict'
> /usr/include/stdio.h:222: `restrict' previously declared here
> /usr/include/stdio.h:223: conflicting types for `restrict'
> [ .... many similar lines omitted .... ]
>
> If I change all "__restrict" in stdio.h to "__restrict__",
> these warnings disappear.
>
> Question: Does anyone know the difference between
> __restrict and __restrict__?
>
__restrict__ is the gcc(1)-only feature. From gcc.info:
: `-std='
: Determine the language standard. This option is currently only
: supported when compiling C or C++. A value for this option must be
: provided; possible values are
: [...]
: Even when this option is not specified, you can still use some of
: the features of newer standards in so far as they do not conflict
: with previous C standards. For example, you may use
: `__restrict__' even when `-std=c99' is not specified.
: [...]
: As with gcc, g++ understands the C99 feature of restricted pointers,
: specified with the `__restrict__', or `__restrict' type qualifier.
: Because you cannot compile C++ by specifying the `-std=c99' language
: flag, `restrict' is not a keyword in C++.
__restrict is defined in <sys/cdefs.h>, it's the FreeBSD feature.
> Should we be using the latter in our system headers?
>
No, we should be using the __restrict as coded. But I wonder why
we can't just use "restrict", please see below.
Note that __restrict is a no-op these days because we don't
compile our C code by default with -std=c99.
I'm not sure why we can't replace
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
#define __restrict
#else
#define __restrict restrict
#endif
#endif
with
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
#define restrict
#endif
and just use "restrict" everywhere. Also similarly I'm not
aware of the status of the CSTD feature for share/mk that
was backed out. (8 makefiles in src/ still have CSTD.)
Cheers,
--
Ruslan Ermilov
FreeBSD committer
ru at FreeBSD.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20040117/45c15114/attachment.bin
More information about the freebsd-hackers
mailing list