如果
根据C99标准,什么情况下会出现"undefined"的结果? 编辑
dot_product
被声明为:float dot_product(const float* restrict a, const float* restrict b, unsigned n);
如果使用以下方式调用它:
dot_product(x, x, x_len)
根据C99标准,什么情况下会出现"undefined"的结果? 编辑
x
是一个指针,它指向 sizeof(float) * x_len
字节的内存,其中 x_len
是无符号整数。这个问题涉及到别名。
const
会影响这一点。 - Chris Hayesdot_product
是点积的常规定义,那么我认为这不会有影响。也就是说,如果您只对指针执行读操作,则违反restrict
不应该有影响。只有在写入时,我才会预期出现问题。 - Chris Hayes