Torquil Macdonald SÃrensen<torquil@gmail.com> writes:
#include "iostream"
#include "blitz/array.h"
int main()
{
blitz::Array<double,1> X(3); X = 0.0;
blitz::Array<double,1> var(1); var = 0.0;
for(int i = 0; i != 1; ++i) {
for(int c = 0; c != 3; ++c) X(c) = double(c);
var(i) = 0.0;
for(int c = 0; c != 3; ++c) var(i) += X(c)*X(c);
var(i) /= 3.0;
}
std::cout<< var(0)<< std::endl;
return(0);
}
---------------------------
If I compile with "-O2", it prints 0, which is wrong.
If I compile with "-O2 -fno-strict-aliasing", it prints the correct answer 1.6666..
In every case I've looked at, when code gives the expected answer only
when using -fno-strict-aliasing, it is because the code is using a type
cast in an invalid way.
In this case I would assume that the invalid type cast occurs in the
blitz library code. Look for invalid type casts there.