mismatched comparison error in XC8

Status
Not open for further replies.

ep.hobbyiest

Full Member level 4
Joined
Jul 24, 2014
Messages
212
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Visit site
Activity points
1,487
i m getting error in in XC8 compiler in if condition.
the error as
Code:
mismatched comparison

and the condition
Code:
            digit[0]--;
            if(digit[0] == 0-1)
                digit[0] = 9;

what is the error then.
 

1. what is the data type of digit
2. what do you intend by the expression 0-1?
arithemtic expression 0 - 1 ? if so its value is -1
0 or 1 ?
 

Declaration is as

Code:
char digit[4]={0};

i want to compare value of -1.

i use such expression but i don't why it is giving error now.
 

XC8 probably defaults type char to unsigned char hence the mismatched comparison warning

as you are going to compare it with -1 try defining digit as a signed char
Code:
signed char digit[4]={0};

general advice is if one is using a char to hold data explicitly define it as signed char (range 0-255) or unsigned char (range -128 to +127) as required
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…