可怕的段错误 [英] The dreaded segfault
问题描述
大家好,
我正在尝试调试以下程序。调试核心文件
在
states = 36,labels = 40的值时,在possibleFlows [i] [k] [m] = 0时显示了segfault。它适用于较小的值。
可能是什么原因?整数溢出或内存不足?我是否b $ b缺少明显的东西?
我使用的是ubuntu和GNU g ++。
int main()
{
const int states = 36,labels = 40;
int fromLabels = labels,toLabels = labels;
int fromStates = states,toStates = states;
int successors [fromStates] [toStates];
int stateMatrix [fromStates] [toStates] [fromLabels] [toLabels];
int possibleFlows [states] [fromLabels] [toLabels];
//将所有可能的流初始化为0
for(int i = 0; i<状态; i ++)
for(int k = 0; k< fromLabels; k ++)
for(int m = 0; m< toLabels; m ++)
possibleFlows [i] [k] [m] = 0; //这里的分段错误
//用给定值填充
// S0
possibleFlows [0] [1] [ 0] = 1;
possibleFlows [0] [2] [0] = 1;
................ ............剩余的
代码............................. .............................................................................................................................
我正在尝试调试以下程序。调试核心文件
在
states = 36,labels = 40的值时,在possibleFlows [i] [k] [m] = 0时显示了segfault。它适用于较小的值。
可能是什么原因?整数溢出或内存不足?我是否b $ b缺少明显的东西?
我使用的是ubuntu和GNU g ++。
int main()
{
const int states = 36,labels = 40;
int fromLabels = labels,toLabels = labels;
int fromStates = states,toStates = states;
int successors [fromStates] [toStates];
这不是合法的C ++,你把它建成C吗?
-
Ian Collins
2008年10月15日星期三19:30:23 -0700(太平洋时间),Prasad
< pr * *********@gmail.com写道:
> int possibleFlows [states] [fromLabels] [toLabels];
//将所有可能的流初始化为0
for(int i = 0; i< states; i ++)
for(int k = 0; k< fromLabels; k ++)
for(int m = 0; m< toLabels; m ++)
possibleFlows [i] [k] [m] = 0; //分段错误这里
我的大脑受伤所以我可能错了,但你可能想尝试......
possibleFlows [m] [k] [i] = 0;
我总是混淆我的多维下标,所以也许你有
到。
10月15日9:39 * pm,Ian Collins< ian-n ... @ hotmail.comwrote:
Prasad写道:
嗨伙计们,
我正在尝试调试以下程序。 *调试核心文件
在
states = 36,labels = 40的值时,在possibleFlows [i] [k] [m] = 0时显示segfault。它适用于较小的值。
可能是什么原因?整数溢出或内存不足?我是否b $ b缺少明显的东西?
我使用的是ubuntu和GNU g ++。
int main()
{
* * const int states = 36,labels = 40;
* * int fromLabels = labels,toLabels = labels;
* * int fromStates = states,toStates = states;
* * int successors [fromStates] [toStates];
这不是合法的C ++,你把它建成C吗?
-
Ian Collins
这是一个c ++程序。我删除了所有名称空间声明,
标题和其他与问题无关的代码。
Hi folks,
I am trying to debug the following program. Debugging the core file
revealed segfault at possibleFlows[i][k][m]=0 when values of
states=36, labels=40. It works fine for lesser values.
What could be the reason? Integer overflow or out of memory? Am i
missing something obvious?
I am using ubuntu and GNU g++.
int main()
{
const int states=36, labels=40;
int fromLabels=labels, toLabels=labels;
int fromStates=states, toStates=states;
int successors[fromStates][toStates];
int stateMatrix[fromStates][toStates][fromLabels][toLabels];
int possibleFlows[states][fromLabels][toLabels];
//Initialise all possible flows to 0
for(int i=0;i<states;i++)
for(int k=0;k<fromLabels;k++)
for(int m=0; m<toLabels;m++)
possibleFlows[i][k][m]=0; //Segmentation fault here
//Populate with given values
//S0
possibleFlows[0][1][0]=1;
possibleFlows[0][2][0]=1;
.........................rest of the
code....................................
Prasad wrote:Hi folks,
I am trying to debug the following program. Debugging the core file
revealed segfault at possibleFlows[i][k][m]=0 when values of
states=36, labels=40. It works fine for lesser values.
What could be the reason? Integer overflow or out of memory? Am i
missing something obvious?
I am using ubuntu and GNU g++.
int main()
{
const int states=36, labels=40;
int fromLabels=labels, toLabels=labels;
int fromStates=states, toStates=states;
int successors[fromStates][toStates];This isn''t legal C++, are you build this as C?
--
Ian Collins
On Wed, 15 Oct 2008 19:30:23 -0700 (PDT), Prasad
<pr**********@gmail.comwrote:
> int possibleFlows[states][fromLabels][toLabels];
//Initialise all possible flows to 0
for(int i=0;i<states;i++)
for(int k=0;k<fromLabels;k++)
for(int m=0; m<toLabels;m++)
possibleFlows[i][k][m]=0; //Segmentation fault hereMy brains hurting so I may be wrong, but you might want to try...
possibleFlows[m][k][i]=0;
I always mix up my multi-dimensional subscripting, so maybe you have
to.
On Oct 15, 9:39*pm, Ian Collins <ian-n...@hotmail.comwrote:Prasad wrote:Hi folks,
I am trying to debug the following program. *Debugging the core file
revealed segfault at possibleFlows[i][k][m]=0 when values of
states=36, labels=40. It works fine for lesser values.
What could be the reason? Integer overflow or out of memory? Am i
missing something obvious?
I am using ubuntu and GNU g++.
int main()
{
* *const int states=36, labels=40;
* *int fromLabels=labels, toLabels=labels;
* *int fromStates=states, toStates=states;
* *int successors[fromStates][toStates];
This isn''t legal C++, are you build this as C?
--
Ian CollinsThis is a c++ program. I have removed all the namespace declaration,
headers and other code which was not relevant to the problem.
这篇关于可怕的段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!