限制关键字和指针内部结构 [英] Restrict Keyword and Pointers inside structs
本文介绍了限制关键字和指针内部结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过使用限制
关键字如下:
int f(int* restrict a, int* restrict b);
我可以指示数组a和b不重叠的编译器。说我有一个结构:
I can instruct the compiler that arrays a and b do not overlap. Say I have a structure:
struct s{
(...)
int* ip;
};
和编写一个函数,需要两个的struct
对象:
and write a function that takes two struct s
objects:
int f2(struct s a, struct s b);
我怎么能同样指示编译器在这种情况下 a.ip
和 b.ip
不重叠?
推荐答案
您也可以使用限制
的结构中。
You can also use restrict
inside a structure.
struct s {
/* ... */
int * restrict ip;
};
int f2(struct s a, struct s b)
{
/* ... */
}
因此编译器可以假定 a.ip
和 b.ip
被用来指不相交的对象在 F2
每次调用函数的持续时间。
Thus a compiler can assume that a.ip
and b.ip
are used to refer to disjoint object for the duration of each invocation of the f2
function.
这篇关于限制关键字和指针内部结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文