### gregr's blog

By gregr, history, 6 weeks ago,

I wrote the code code for the problem problem which is giving WA on test 4. I tried running it locally but it is giving me correct ans.

• 0

 » 6 weeks ago, # |   +1 You have undefined behaviour. Use the command line arguments of g++ to detect it.
•  » » 6 weeks ago, # ^ |   0 Can you please elaborate on same.
•  » » » 6 weeks ago, # ^ |   0 I may be wrong but here they go :use g++ -std=c++17 -Wall -O myfilename.cpp -o myexecutable -Wall arguement to include warnings (It shows useful warnings like uninitialized/unused vars) -O to optimize your code (I don't know about this one) By default gcc names the executable as a.out(a.exe in windows) but -o is used to change the a.out to desired name replace myexecutable to anything you want. Generally name of cpp file without .cpp extention is used to name the executable with the same name as the file being compiled. P.S : Please correct me if I am wrong
•  » » » » 6 weeks ago, # ^ |   0 Thanks a lot !! I will check it and get back to you. !!
•  » » » » 5 weeks ago, # ^ |   0 Useful is also -fsanitize=address and it's family.In C++ if you access an array out of bounds (A[10] if A only has length 5) or similar, it is not guaranteed to throw some kind of error, it's just undefined behavior. If you really can't access the memory, it is a segmentation fault, but if you can, it might let you access and change that.If you compile with -fsanitize=address and then your program does something like that, it will output a lot of crap on the screen, but it allows you to pinpoint where the error happens.
•  » » » » » 5 weeks ago, # ^ |   0 Thank You It's a very useful information. Most of my errors are Segmentation fault or similar I would just end up retyping everything from start or worse give up.