I want to perform math compares using constants so that we test that the compare operation performs correctly. The compiler obviously recognizes that the compare operation produces a true result with the constants given so it doesn't generate any code for it. What can I specify to the compiler to tell it to generate code for what it sees and not perform any optimization? Here is an example piece of the code:
BOOL BoolResult = FALSE; /*--------------------------------------------------- * integer compare operations *---------------------------------------------------*/ if ( (10000 < 20000) && (20000 <= 30000) && (30000 > 25000) && (25000 >= 20000) && (20000 == 20000) && (20000 != 20001) ) { BoolResult = TRUE; }
You could move the comparisons into separate functions and hope that the compiler doesn't inline them:
BOOL less(int a, int b) { return a < b ? TRUE : FALSE; } BOOL more(int a, int b) { return a > b ? TRUE : FALSE; }
And so on. Then use these functions instead of the comparison operators. After testing, you can use macros to 'inline' the functions.