[SDL] Strangle problem using keys

Justin Coleman jmcoleman at gmail.com
Tue Nov 1 13:14:50 PST 2005

On 11/1/05, ALTAIR - <altairdiv at hotmail.com> wrote:
> If (keys[SDLK_UP]== 1)
> is the same what:
> If (keys[SDLK_UP])

No, it's not the same. The first statement is true if and only if
(keys[SDLK_UP]) is exactly 1. The second statement is true as long as
(keys[SDLK_UP]) evaluates to any non-zero value.

For the cases of 0 and 1 they are equivalent, but if (keys[SDLK_UP])
is 2 or more, or any negative number, or any float value (I don't
think it's a float variable but the point is worth making here), then
the statement will still evaluate to true.

If you're using the actual value of (keys[SDLK_UP]) in a calculation
or control statement somewhere and thus always expect (or require) it
to be 1 or 0, the first is okay. If you only care about true or false,
use the second form.


More information about the SDL mailing list