Zilog EZ80F916 User Manual
Page 93

UM014423-0607
Using the Integrated Development Environment
ZiLOG Developer Studio II
eZ80Acclaim!
®
User Manual
73
int int2;
char ch1 = -2;
char *neq_str = "NOT EQUAL";
char *eq_str = "EQUAL";
int main(void)
{
puts("START");
int1 = uch1 - uch2;
if (int1 != -1)
puts(neq_str);
//nopromote:00FFh != FFFFh
else
puts(eq_str);
//promote: FFFFh == FFFFh
int2 = ~uch3;
if (int2 != ~128)
puts(neq_str);
//nopromote:007Fh != FF7Fh
else
puts(eq_str);
//promote: FF7Fh == FF7Fh
int2 = -uch3;
if (int2 != -128)
puts(neq_str);
//nopromote:0080h != FF80h
else
puts(eq_str);
//promote: FF80h == FF80h
if (uch3 < ch1)
puts("UNSIGNED");
//nopromote:(uchar)80h < (uchar)FEh
else
puts("SIGNED");
//promote: (int) 128 > (int) -2
puts("DONE.");
}
The following recommended programming practices are good practice in any case for pro-
ducing code that is both correct and efficient. These practices are especially important to
avoid trouble if you are using the deprecated Disable ANSI Promotions option:
•
Use variables of type char or unsigned char wherever the expected range of values for
the variable is [
-
128..127] or [0..255], respectively.
•
Use explicit casts (to int, unsigned int, long or unsigned long) where the result of an
expression is expected to overflow the larger of the two operand types. (Even with
ANSI promotions disabled, the compiler automatically promotes a smaller operand so
that the types of the operands match.)