restrict
https://baike.baidu.com/item/restrict/7384270?fr=aladdin
关键字restrict:
- 告诉编译器所有修改该指针所指向内存中内容的操作都会通过该指针来修改,而不会通过其它途径(其它变量或指针)来修改,方便编译器做出优化;
- 然而,编译器不会检查您是否遵循了这一限制,所以必须由程序员自己来遵循规范;
实例1:
//~/C++/restrict/restrict_1.c
//编译命令:gcc restrict_1.c -o restrict -std=c99
//以下代码能够编译通过,说明编译器不会检查您是否遵循了这一限制
#include <stdio.h>
void m_restrict(int *restrict a, int *restrict b)
{
*a = 5;
*b = 6;
printf("restrict\n");
}
int main()
{
int num1 =