Note that the first is already enough to render the entire program invalid. Crashes or seemingly random crashes are one possible manifestation of undefined behaviour.Īs far as I can see, you have two instances of undefined behaviour in your code. In contrast to certain other languages, C++ sometimes leaves the behaviour of the program to the compiler or to the operating system when you make critical programming errors, such as trying to access memory you are not supposed to access. It crashed after I tested it with some more or less random input (I just entered 12, 2 and 2).īy avoiding what C++ calls undefined behaviour.
I just tried it on MSVC 2013 on my Windows 7 64-bit machine with /EHsc /Za. Second, if by “stack smashing error” you mean a segmentation fault, the program crashes “on Windows” as well. And that compilers have different versions and endless combinations of different invocation options.
Not to mention that “Windows” could, in theory, be everything from Windows 1 to Windows 10 and that “Ubuntu” is hardly a very precise definition, either. There is more than one compiler available on any of those systems. But in Ubuntu i get stack smashing error everyįirst of all, stating the name of your operating system is not enough. If (result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal)=0.5)Įlse printf("%.0f", result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal)) If (min_elem(result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal),result(pawn_start_vertical,pawn_start_horizontal+1,knight_start_vertical,knight_start_horizontal))=0.5)Įlse printf("%0.f",min_elem(result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal),result(pawn_start_vertical,pawn_start_horizontal+1,knight_start_vertical,knight_start_horizontal))) Pawn_start_vertical = int(pawn_start)-96 Knight_start_vertical = int(knight_start)-96 Hi, I am working on a small project that will involve a modbus/TCP device, to make sure it is working I am just monitoring one of the channels and displaying it on a graph. Scanf("%c%d%*c%c%d%*c", &pawn_start, &pawn_start_horizontal, &knight_start, &knight_start_horizontal) Int knight_start_horizontal, pawn_start_horizontal, knight_start_vertical, pawn_start_vertical Return (max_elem(max_elem(a,b),max_elem(c,d))) Result_array = result(pawn_v, pawn_h, knight_v - 1, knight_h - 2) Ī = max_elem(result_array,result_array) ī = max_elem(result_array,result_array) Ĭ = max_elem(result_array,result_array) ĭ = max_elem(result_array,result_array) Result_array = result(pawn_v, pawn_h, knight_v + 1, knight_h - 2)
Result_array = result(pawn_v, pawn_h, knight_v - 1, knight_h + 2)
Result_array = result(pawn_v, pawn_h, knight_v + 1, knight_h + 2) Result_array = result(pawn_v, pawn_h, knight_v - 2, knight_h - 1) Result_array = result(pawn_v, pawn_h, knight_v - 2, knight_h + 1) Result_array = result(pawn_v, pawn_h, knight_v + 2, knight_h - 1)
Result_array = result(pawn_v, pawn_h, knight_v + 2, knight_h + 1) What is the reason for the above behavior? Any pointers is appreciated.Double result (int pawn_v, int pawn_h, int knight_v, int knight_h)Įlse if ((pawn_v = knight_v + 2) & (pawn_h = knight_h + 1))Įlse if ((pawn_v = knight_v + 2) & (pawn_h = knight_h - 1))Įlse if ((pawn_v = knight_v - 2) & (pawn_h = knight_h + 1))Įlse if ((pawn_v = knight_v - 2) & (pawn_h = knight_h - 1))Įlse if ((pawn_v = knight_v + 1) & (pawn_h = knight_h + 2))Įlse if ((pawn_v = knight_v + 1) & (pawn_h = knight_h - 2))Įlse if ((pawn_v = knight_v - 1) & (pawn_h = knight_h + 2))Įlse if ((pawn_v = knight_v - 1) & (pawn_h = knight_h - 2))Įlse if ((pawn_v = knight_v) & (pawn_h = knight_h))
The line number 1100, is the line where I am doing the fclose() in the above code segment.