简体   繁体   English

负指数分割错误

[英]segmentation fault with negative index

This code fragment gives segfault on the line with ->, please note n=3 该代码片段使用->在段上给出了段错误,请注意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) 有人告诉我这是因为我使用的是64位(Linux amd64,gcc 4.6,调试标志-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 这与将索引的二进制补码值添加到地址有关,它可以在32位上正常工作,但不能在64位上工作

Detailed here: http://www.devx.com/tips/Tip/41349 此处详细介绍: http : //www.devx.com/tips/Tip/41349

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM