Ran into a fun situation today where I was writing some code, and I came across an interesting situation in C++. Now, before I get to the end of this post, I’ll give you the punch-line, Developer stupidity.
So I was working on a exercise where I needed to write some sort of state machine.
|
|
In this code STATE_3 is never reached. The code for the enum was working fine, but the state wasn’t being reached. I went over this for a while, until I found out the problem.
|
|
The assignment for the state variable had been left over from a previous implementation of the code, and when you set the Boolean value for state = 2;, you get 1, which is true.
Now I don’t expect anyone to be as silly as me and make this mistake, but just in case, learn from my lesson.