I am working on a program where the code exceeds the ROM space by ~1K. I'm trying to reduce the size of my program.
There is a lot of code that checks the state of a binary Flag.
Code:
int flag = 1;
do something; //This may change the state of flag.
if (flag == 0) do something;
else
do something else;
Since the state of the flag can be 1, or 0, I can write the decision block as:
Code:
if (flag == 0) do something;
or
if (flag != 1) do something;
or
if (flag < 1) do something;
Also which is better.
Code:
int zero = 0;
int flag = 1;
do something; //This may change the state of flag.
if (flag == zero) do something;
else
do something else;
or
Code:
int flag = 1;
do something; //This may change the state of flag.
if (flag == 0) do something;
else
do something else;
This code is repeated many times using different binary variables for the flag function, So a few bytes savings is multiplied.