I need to check a variable vi_theIndex for its value. At the given moment it has a value of 65.
I want to check if vi_theIndex is bigger or equal to zero AND smaller than 32.
Right now I do it like this:
long long vi_theIndex = 65;
if ((vi_theIndex >= 0) && (vi_theIndex < 32) )
{
//Case true
}
else
{
//Case false
}
I realized that the results are wrong for 65. The second case should come up but the first case becomes true. Why is this?
I tried this:
long long vi_theIndex = 65;
bool limitFlag1, limitFlag2;
limitFlag1 = (vi_theIndex <= 0);
limitFlag2 = (vi_theIndex = 65);
limitFlag2 becomes true and limitFlag1 becomes undefined, the debugger doesn´t even stop there on my breakpoint. It looks like C doesn´t understand the ‘<‘, ‘<=’ or ‘>’ signs. This also happens when I use the ‘<‘ or ‘>’ sign alone like here:
limitFlag1 = (vi_theIndex < 0);
limitFlag1 is not defined.
Can somebody please shed some light on this?
You must not be showing your real code for your first example – as you say, “case false” should be executed.
Your second example has a problem – you have
vi_theIndex = 65, rather thanvi_theIndex == 65, which you probably meant. The statement as you have it is always true.limitFlag1will be0– I’m not sure what you mean by it “becomes undefined” – are you not showing your real code here, too?