# unexpected result: zero minus zero is greater than 10

Found some unexpected (for me) behavior in the IDE 1.0.5.
Tracked down my problem to one line of code:

``````#defined MAXROW = 10
uint16_t fileCount = 0
uint8_t   listStart = 0
MAXROW < (fileCount - listStart)  evaluates to TRUE
``````

Somehow, I don’t see how 10 is less than zero minus zero.
I recast listStart to uint16_t and now 10 is greater than zero.
What gives?

try to print to the console, maybe it will help you see what is happening! vanduino:

``````#defined MAXROW = 10
``````

That's not how to write a #define

``````#define MAXROW 10
``````

Please post a complete sketch that actually compiles and that illustrates the problem. Shorter is better.

I'm guessing this is a typo from when you posted message?

``````#defined MAXROW = 10
``````

vanduino:
Found some unexpected (for me) behavior in the IDE 1.0.5.
Tracked down my problem to one line of code:

``````#defined MAXROW = 10
``````

uint16_t fileCount = 0
uint8_t   listStart = 0
MAXROW < (fileCount - listStart)  evaluates to TRUE

``````

Somehow, I don't see how 10 is less than zero minus zero.
I recast listStart to uint16_t and now 10 is greater than zero.
What gives?
``````

You are subtracting an 8 bit variable from a 16 bit variable to compare to what?

vanduino:
Found some unexpected (for me) behavior in the IDE 1.0.5.
Tracked down my problem to one line of code:

``````#defined MAXROW = 10
``````

uint16_t fileCount = 0
uint8_t   listStart = 0
MAXROW < (fileCount - listStart)  evaluates to TRUE

Four lines of pseudo-code.

Please post a sketch that actually compiles, and displays this problem.

Plus what Jack Christensen said. Yes, just a typo,
The code was embedded in a lot of verbosity. I isolated the line and bracketed it with print statements and yes, with all the constants and variables revealed, zero minus zero was greater than 10. Until I recast the uint8_t zero to uint16_t zero. Then 10 was greater than zero, like in the olden days.

I'll make a new sketch and try to recreate the behavior.

Glad I'm not the only one that does that vanduino:
Yes, just a typo,
The code was embedded in a lot of verbosity. I isolated the line and bracketed it with print statements and yes, with all the constants and variables revealed, zero minus zero was greater than 10. Until I recast the uint8_t zero to uint16_t zero. Then 10 was greater than zero, like in the olden days.

I'll make a new sketch and try to recreate the behavior.

Mixed type math gave bad results back in the day too. That's why I spotted that.

vanduino:
The code was embedded in a lot of verbosity. I isolated the line and bracketed it with print statements and yes, with all the constants and variables revealed, zero minus zero was greater than 10. Until I recast the uint8_t zero to uint16_t zero. Then 10 was greater than zero, like in the olden days.

I look forwards to the proof. no need to cast, compiler is clever enough …

``````#define MAXROW 10

void setup()
{
Serial.begin(115200);

uint16_t fileCount = 0;
uint8_t   listStart = 0;

if (MAXROW < (fileCount - listStart)) Serial.print("TRUE");
else Serial.print("FALSE");
}

void loop()
{
}
``````