Так что я читал, что лязг намного более строгие стандарты implimentation, но это действительно сбивает с толку меня ...Сегментация Fault, ранее не существует при компиляции с GNU, теперь с помощью Clang
void readInputFile(const string inputFileName, Geometry &planeGeom, FlightConditions &FC, AircraftChar & aeroChar,
vector<string> &runFileResults, int &vorlaxRun, int &lateralTrue)
{
int inputRuns;
char infile[32], blank, cTest[32], iTest[32];
char aircraftInpFile[80];
char vorlaxCommand[80];
string casTest, inpTest;
double S_ref,span,Cbar,Xbar,Zbar,St_ref,mac_t,Sf_ref,CD_0,Mach,Uinf,rho;
FILE *ofpInput;
strcpy(infile,inputFileName.c_str());
ofpInput = fopen(infile, "r");
assert(ofpInput!=NULL);
fscanf(ofpInput, "%i", &lateralTrue); //0--false only longitudinal analysis, 1--true long and lateral
printf("lateralTrue = %i\n",lateralTrue);
fscanf(ofpInput, "%i", &vorlaxRun); //0--false will input aero data, 1--true will input run files and execute vorlax
printf("Are we running Vorlax? -- %i\n",vorlaxRun);
fscanf(ofpInput, "%i", &inputRuns); //for looping to run all the needed vorlax files
printf("inputRuns = %i\n",inputRuns);
runFileResults.resize(2*inputRuns);
cout << "I made it to the part where I am reading" << vorlaxRun << "\n" << endl;
fscanf(ofpInput, "%s", &blank); //reading in data from input file
fscanf(ofpInput, "%lf %s", &planeGeom.S, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.b, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.cBar, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.xBar, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.zBar, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.St, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.mact, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.Sf, &blank);
fscanf(ofpInput, "%lf %s", &aeroChar.CD_0, &blank);
fscanf(ofpInput, "%lf %s", &aeroChar.e, &blank);
fscanf(ofpInput, "%lf %s", &FC.mach, &blank);
fscanf(ofpInput, "%lf %s", &FC.uinf, &blank);
fscanf(ofpInput, "%lf %s", &FC.rho, &blank);
fscanf(ofpInput, "%lf %s", &FC.alpha, &blank);
fscanf(ofpInput, "%lf %s", &aeroChar.dEdA, &blank);
cout << "I made it past reading all the planeGeom stuff " << vorlaxRun << "\n" << endl;
//Commented out code section for debugging purposes...
cout << "I made it past reading all the aeroChar stuff" << "\n" << endl;
Так что, казалось, что int vorlaxRun вызывал проблемы довольно странно, поэтому я добавил его к своим отпечаткам (как вы видите выше), чтобы посмотреть, что происходит, и это результат, который я получаю.
Reading inputFileMavericAftCGApproachFlapsDown.dat
lateralTrue = 0
Are we running Vorlax? -- 0
inputRuns = 0
I made it to the part where I am reading0
Segmentation fault: 11
Если я вынимаю второй экземпляр vorlaxRun печатается это то, что я получаю
Reading inputFileMavericAftCGApproachFlapsDown.dat
lateralTrue = 0
Are we running Vorlax? -- 0
inputRuns = 0
I made it to the part where I am reading0
I made it past reading all the planeGeom stuff
I made it past reading all the aeroChar stuff
Abort trap: 6
Я думаю, что я бы ожидать прерывания ловушку 6, так как я должен был закомментировать кучу строк в процесс наблюдения за происходящим. Но я не понимаю, почему удаление второго экземпляра печати переменного на экран, приводивших волшебно работать ... или почему, если добавить его в самом последних соиЬ тогда я получаю это:
Reading inputFileMavericAftCGApproachFlapsDown.dat
lateralTrue = 0
Are we running Vorlax? -- 0
inputRuns = 0
I made it to the part where I am reading0
I made it past reading all the planeGeom stuff
Segmentation fault: 11
Надеемся Я предоставил достаточно информации. Я совершенно новичок в clang, и у меня никогда не было никаких проблем с этим в g ++ после поиска и поиска. Я все еще потерял ...
Почему вы смешиваете код C с C++? –
Скомпилируйте все предупреждения и информацию об отладке (например, 'g ++ -Wall -g' или' clang -Wall -g'). Я не читал ваш код, но, похоже, у вас есть [неопределенное поведение] (https://en.wikipedia.org/wiki/Undefined_behavior). Используйте debugger 'gdb' –
' fscanf (ofpInput,% s "и пробел);' очень вероятно [неопределенное поведение] (https://en.wikipedia.org/wiki/Undefined_behavior) –