Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

Bhj2001's blog

By Bhj2001, history, 4 weeks ago, In English,
 #pragma GCC optimize ("trapv") // kills the program on integer overflows (but is really slow).

This helps a lot in testing. If a solution fails on a particular test case this can help in finding the bug.
This works on my computer but does not work on Codeforces.
Is there an alternative to this on online judges?

 
 
 
 
  • Vote: I like it
  • +38
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

This is very useful option indeed, just remember, that it does not work with unsigned integers and with casts

»
4 weeks ago, # |
Rev. 2   Vote: I like it +17 Vote: I do not like it

I compile with these flags and one of them turns on checking for overflows (but slows the program down too). This won't likely help you when submitting to an online judge :(

g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG

»
4 weeks ago, # |
Rev. 2   Vote: I like it +17 Vote: I do not like it

On Codeforces, you can submit with the compiler "Clang++ 17 Diagnostics", which have much more checking than just integer overflow error. However, because test cases on Codeforces are large, you might get time limit exceeded before getting to the desired test case.


See also: Catching silly mistakes with GCC — Codeforces (including tips on how to check integer overflow, array out of bound error, check for precondition in STL algorithm, turn on warnings, etc.)