segmentation fault with negative index
This code fragment gives segfault on the line with ->, please note n=3
real_t _b[n+1];
real_t * b = 开发者_开发问答_b+1;
std::fill( b, b + n , (real_t)0.0 );
for ( unsigned c = 0; c < n; c ++ )
{
-> b[c-1] = 0; b[c] = 1;
Lsolve( xtmp, lu, b, n );
I'm told this is because I'm in 64-bit (Linux amd64, gcc 4.6, debug flag -O0)
anyone could tell me more?
It's to do with the two's complement value of the index being added to the address, it works fine in 32 bit but not 64
Detailed here: http://www.devx.com/tips/Tip/41349
精彩评论