6

dot_productとして宣言されている場合

float dot_product(const float* restrict a, const float* restrict b, unsigned n);

でそれを呼び出すだろう

dot_product(x, x, x_len)

C99標準に従って、「未定義」になりますか?

編集

xsizeof(float) * x_lenもちろん、メモリのバイトを指すポインターx_lenですunsigned。この質問はエイリアシングに関するものです。

4

3 に答える 3

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.

これは、エイリアス化されたポインターが読み取り専用アクセスに使用されている場合、定義された動作を持つものとして質問した形式の関数を明確に呼び出すようです。エイリアス化されたポインターのいずれかを介して書き込むと、未定義の動作が呼び出されます。

于 2013-12-18T09:45:18.223 に答える