Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

mismatched comparison error in XC8

Status
Not open for further replies.

ep.hobbyiest

Full Member level 4
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top