别名"const restrict"指针参数是否合法?

Max*_*axB 6 c pointers c99 pointer-aliasing restrict-qualifier

如果dot_product声明为

float dot_product(const float* restrict a, const float* restrict b, unsigned n);
Run Code Online (Sandbox Code Playgroud)

会打电话给

dot_product(x, x, x_len)
Run Code Online (Sandbox Code Playgroud)

根据C99标准,"未定义"?

编辑

x是一个指针,当然,指向sizeof(float) * x_len内存的字节,x_lenunsigned.这个问题是关于别名的.

Chr*_*yes 6

我没有原始的C99(即ISO9899:1999)文字; 我只有一份ISO9899:2007:TC3.我希望从该文件的第111页开始的这篇文章与C99标准中的文字非常相似.

6.7.3.1 Formal definition of restrict

...

10. EXAMPLE 3

The function parameter declarations

    void h(int n, int * restrict p, int * restrict q, int * restrict r)
    {
        int i;
        for (i = 0; i < n; i++)
            p[i] = q[i] + r[i];
    }

illustrate how an unmodified object can be aliased through two restricted
pointers. In particular, if a and b are disjoint arrays, a call of the form
h(100, a, b, b) has defined behavior, because array b is not modified within
function h.
Run Code Online (Sandbox Code Playgroud)

如果别名指针用于只读访问,这似乎清楚地调出了您所询问的具有已定义行为的表单的函数.通过任何一个别名指针写入将调用未定义的行为.