C++ 变量不为null但在'callq'上时出现分段错误`
问题的最新情况: 这是我在str1_h[0][j]=bar1str1_c[j]上接收SIGSEV的SSCCE;。我使用gdb检查的所有变量都不是空的:C++ 变量不为null但在'callq'上时出现分段错误`,c++,segmentation-fault,C++,Segmentation Fault,问题的最新情况: 这是我在str1_h[0][j]=bar1str1_c[j]上接收SIGSEV的SSCCE;。我使用gdb检查的所有变量都不是空的: #include <fstream> //ifstream and ofilestream using namespace std; int bar1(int); int bar2(int); int bar3(int); int main() { string str1 = "string"; ifstrea
#include <fstream> //ifstream and ofilestream
using namespace std;
int bar1(int);
int bar2(int);
int bar3(int);
int main() {
string str1 = "string";
ifstream ifs;
ifs.open("./file.txt");
string line, str2;
while (!ifs.eof()) {
ifs >> line;
str2 += line;
}
ifs.close();
unsigned str2_l = str2.length();
unsigned str1_l = str1.length();
unsigned n = str2_l - str1_l + 1;
int str1_c[4];
str1_c[0] = 0;
str1_c[1] = 0;
str1_c[2] = 0;
str1_c[3] = 0;
int x[3][4][n];
int str1_h[3][4];
for (unsigned j = 0; j < 4; j++) {
str1_h[0][j] = bar1(str1_c[j]);
str1_h[1][j] = bar2(str1_c[j]);
str1_h[2][j] = bar3(str1_c[j]);
for (unsigned i = 0; i < n; i++) {
x[0][j][i] = bar1(0);
x[1][j][i] = bar2(0);
x[2][j][i] = bar3(0);
}
}
}
int bar1(int x) {
return 0;
}
int bar2(int x) {
return 0;
}
int bar3(int x) {
return 0;
}
你可以在C++中:
可以使用new,也可以使用STL容器,例如std::vector。另见
您的数组x位于堆栈上,因此写入此数组可能会覆盖堆栈上的重要值,例如返回指针等。您的算法是递归的吗?在调用过程中崩溃可能意味着堆栈溢出。请尝试创建并向我们显示。或者至少向我们展示相关的声明和初始化,以及相关变量(如j)的实际值。你能分步除法吗?在ITA的第一行放一个断点。注意,非指针值不能为空,因此将它们与之进行比较是毫无意义的。@Jean-Françoisfare它不是递归的
int x[3][4][n];