use*_*683 17 c struct function restrict-qualifier
通过使用这样的restrict关键字:
int f(int* restrict a, int* restrict b);
Run Code Online (Sandbox Code Playgroud)
我可以指示编译器数组a和b不重叠.说我有一个结构:
struct s{
(...)
int* ip;
};
Run Code Online (Sandbox Code Playgroud)
并编写一个带有两个struct s对象的函数:
int f2(struct s a, struct s b);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我怎样才能类似地指示编译器a.ip并且b.ip不重叠?
md5*_*md5 15
您也可以restrict在结构内部使用.
struct s {
/* ... */
int * restrict ip;
};
int f2(struct s a, struct s b)
{
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
因此,编译器可以假设a.ip并且b.ip在每次调用f2函数的持续时间内用于引用不相交的对象.