restrict C99 restricted pointers

restrict C99 restricted pointers

C99's restrict promises exclusive object access during association, enabling optimization. Overlaps violating this promise cause undefined behavior.

CategoryType qualifiers
KindKeyword / Statement
C standardC99

📝 Syntax

void copy(int * restrict dst, const int * restrict src, int n);

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

2 4 6

📚 Related Tutorials

❓ FAQ

QWhat happens when overlapping memory is passed to restrict pointers?
AIf the accesses violate restrict's exclusive-access contract, the program has undefined behavior; the compiler does not check overlap for the caller. Use memmove, whose semantics support overlap, rather than this example's interface for potentially overlapping buffers.
QDoes restrict check pointer overlap at runtime?
ANo. It is a semantic promise from the programmer to the compiler that enables optimization, with no runtime detection. The caller must ensure that every invocation satisfies the contract.
QIs it a violation for two restrict pointers only to read the same object?
AIf the object is not modified during the relevant period, reads through two restricted pointers alone do not create this exclusivity conflict. If one pointer also modifies the object, aliased accesses may violate the promise, so analyze the complete access sequence.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏