Re: What does 'restrict' mean?
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Mon, 03 Apr 2006 11:39:39 GMT
Niu Xiao wrote:
I see a lot of use in function declarations, such as
size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE*
restrict fp);
but what does the keyword 'restrict' mean?
there is no definition found
in K&R 2nd.
Consider the types of memcpy and memmove:
void *memcpy (void * restrict s1, const void * restrict s2, size_t n);
void *memmove(void * s1, const void * s2, size_t n);
The reason that memcpy has the restrict keyword and memmove doesn't
is because the parameters don't overlap in memcpy,
but they are allowed to, in memmove.
What it means is that in memcpy,
all accesses to the object pointed by s1,
will be made from s1 or pointers derived from s1
and that all accesses to the object pointed to by s2
will be made from s2 or pointers derived from s2.
There may or may not be optimizations available
because of that. Bear in mind that standard library functions
can be written in assembley langauge or any language.
In memmove, because the objects may overlap,
it's possible to be accessing both objects at the same time
with the same pointer.
--
pete
.
- References:
- What does 'restrict' mean?
- From: Niu Xiao
- What does 'restrict' mean?
- Prev by Date: Ncurses
- Next by Date: Re: How to Define High-precision Date type
- Previous by thread: What does 'restrict' mean?
- Next by thread: Re: What does 'restrict' mean?
- Index(es):
Relevant Pages
|