开发者

segmentation fault with negative index

开发者 https://www.devze.com 2023-03-25 18:15 出处:网络
This code fragment gives segfault on the line with ->, please note n=3 real_t _b[n+1]; real_t * b = 开发者_开发问答_b+1;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消