What does __restrict do?

Erik Trulsson ertr1013 at student.uu.se
Tue Feb 10 13:19:44 PST 2004


On Tue, Feb 10, 2004 at 02:35:58PM -0500, Bill Moran wrote:
> In various places in the source code, for example, in the code for printf():
> 
> printf(char const * __restrict fmt, ...)
> 
> I understand everything except __restrict.  What does that mean/do?  Is it
> a FreeBSDism?  (I can't find anything about it in any C docs)

'__restrict' is a macro that expands to either 'restrict' if the
compiler used supports that keyword, or to the empty string otherwise.

'restrict' is a standard C keyword since 1999, and is essentially used
to inform the compiler that two pointers don't alias each other and
that the compiler is therefore free to perform certain optimizations
that otherwise might not be legal.
It is just a hint to the compiler, and can always be removed (but not
necessarily added) without changing the semantics of a program.

Any C book that covers C99 should contain a more complete explanation.


-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se


More information about the freebsd-questions mailing list