28

This came from a friend of mine who found this in a code repo at work.

Comments
  • 1
    What the actual fuck?!?! 😨
  • 4
    i always wanted to propose a suicide risk assessment method for developers from their code.
    This one earns a high score.
  • 7
    This is not even guaranteed to fail since optimizing compilers will just remove that block of code.

    Integer division by zero is undefined behaviour. Compilers will assume undefined behaviour can never happen, thus they assume the pool can never overflow, thus convincing themselves that the conditional is dead code and remove it.
  • 1
    1. Why recreate malloc?
    2. Isn't it meant to return a null pointer in that case?
  • 3
    "C++ is a highly flexible language which can allow for very efficient programmes"

    ... can .... CAN
  • 2
    No clue what this code is for
  • 1
    How old are u if IAM allowed to ask?
  • 2
    Instead of throwing an exception let's divide by 0? Does that even halt execution if you don't catch any exceptions?
  • 0
  • 0
    @Zennoe Some compiler will optimize it away, or won't even compile and just cry.
  • 1
    @Zennoe Oh, sorry, miss read your Question.

    It's undefined behaviour, but I think most will halt execution.

    But its undefined behaviour so who knows?
  • 1
    @CompileNix May u want to talk while coding, because I am searching someone to talk about coding
  • 0
    @Batburger there are GCC options for controlling the behaviour of the compiler (not just the infamous -ffast-maths) but I haven't looked into it nor do I know the default behaviour. That's why I asked.
Add Comment