When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

paranoidninja's blog

By paranoidninja, history, 5 years ago, In English

I code in JAVA. Recently, in a CodeForces contest, I went on hacking a solution and discovered a C++ code that might face an array index out of bound error but it didn't. Later found out that there is no array index out of bound error in C++ and needs to be taken care of while coding. Due to this, my hack was unsuccessful. Basically my question is what things I need to take care of while hacking a C++ code if I code in other language? Do I need to start coding in other language? Most of the coders use C++ so I find it difficult to find a JAVA solution to hack.

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

| Write comment?
»
5 years ago, # |
  Vote: I like it -19 Vote: I do not like it

LoOoOOoOLoOoOooOLoOooOoOooL. LMAO. ROFL. How do you even hack something that you dont understand? XD.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    Because syntax is somewhat similar for both languages. Not that I'm totally unaware of what happens in C++. I just don't use it regularly that's why I was unfamiliar of the problem during hacking. Please think before commenting on any post and come up with a relevant answer.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Runtime checks slows program and design philosophy of C++ primarily focuses upon maximal speed. On the other hand language assumes that programmer knows and is aware of what he is doing.

If you want warnings for out of bound access then compiler flags can help.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

When you do something wrong in C++ such as accessing elements out of the array bounds, you will mostly face undefined behavior and not a runtime error. So sometimes you can't easily hack these without having the code in your editor to check if it fails. And it might differ on Codeforces or other OJs, so run the code in that OJ if possible. Otherwise, it's mostly a gambling thing.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    But typing the code back again would consume a lot of time. That's why I looking for similar things to take care of while hacking. Thanks anyways.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Just to mention that even the same code on the same OJ can behave differently when doing Undefined behaviour on multiple runs.