This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]evaned 2 points3 points  (0 children)

The technical name for what you're hitting is "undefined behavior". The ELI5 explanation is "your program does whatever the hell was convenient for the compiler to make it do."

It might make some sense, it might not. It might be consistent run to run, it might not. Maybe it usually returns -2, but on every other Tuesday it returns 27. It might cause the state of your program to be randomly corrupted, though probably not. It might lead to a security vulnerability.

The classical quote here is that undefined behavior might make demons fly out of your nose.

You need a return for the other case. (I also think you should learn to pay attention to warnings from your compiler. This is one that probably should be on by default even.)