Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Jan 2004 03:58:10 +0200
From:      Ruslan Ermilov <ru@FreeBSD.org>
To:        Tim Kientzle <kientzle@acm.org>
Cc:        Mike Barcroft <mike@FreeBSD.org>
Subject:   Re: __restrict__  vs __restrict ?
Message-ID:  <20040117015809.GJ9410@FreeBSD.org.ua>
In-Reply-To: <40088E75.5080908@acm.org>
References:  <40088E75.5080908@acm.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--aznLbwQ42o7LEaqN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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:
>=20
> > cat test.c
> #include <stdio.h>
> > gcc -std=3Dc99 -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 .... ]
>=20
> If I change all "__restrict" in stdio.h to "__restrict__",
> these warnings disappear.
>=20
> Question:  Does anyone know the difference between
> __restrict and __restrict__?
>=20
__restrict__ is the gcc(1)-only feature.  From gcc.info:

: `-std=3D'
:      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=3Dc99' 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=3Dc99' 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?
>=20
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=3Dc99.

I'm not sure why we can't replace

#if !(__GNUC__ =3D=3D 2 && __GNUC_MINOR__ =3D=3D 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,
--=20
Ruslan Ermilov
FreeBSD committer
ru@FreeBSD.org

--aznLbwQ42o7LEaqN
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFACJaxUkv4P6juNwoRAs8QAJ4+VXlFcR/iCq0xuCb6dvyABDbLjQCcCP7F
IJw2dMYDsvDokd5XAwek8Qw=
=/VgN
-----END PGP SIGNATURE-----

--aznLbwQ42o7LEaqN--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040117015809.GJ9410>