我正在做很多矩阵运算,并希望利用 C99 的restrict
指针限定符。
我想将我的矩阵设置为指向指针的指针,以便于下标,如下所示:
int **A = malloc (ncols * sizeof(int *));
A[0] = malloc (nrows * ncols * sizof(int));
for (int i=1; i < ncols; i++) {
A[i] = A[0] + i*nrows;
}
现在,对于矩阵乘法函数
void mmultiply ( int nrows, int ncols, int **Out, int **A, int **B);
我必须将参数的两个指针都限定为受限吗?这是有效的语法,但我很难确定int *restrict *restrict
其行为是否与int **restrict
.
那么,在正确限制指针的情况下,是否通过A[0][col*nrows + row]
undefined 访问元素?(即,编译器是否会假设我只通过这样A[col][row]
的值访问矩阵)?还是我必须保持一致?row
row < nrow