I have the following code:
int byte_align(void * ptr)
{
int power = 2, n = 1, result = 0;
size_t address = reinterpret_cast<size_t>(ptr);
while(address%power == 0)
{
power *=2;
result = n;
n++;
}
return result;
}
当我在Ubuntu上使用g++4.6编译并使用-O3优化参数执行该函数时,每次运行都会得到不同的双精度变量值(4、5、7、8)。为什么呢?在另一台具有相同操作系统和编译器的计算机上,我总是得到3作为结果。
这些结果可能的其他原因是什么?
谢谢!
double x; func(&x);
。 - arc_lupus