CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Why does 0 != 0?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
epv



Joined: 23 Feb 2008
Posts: 8

View user's profile Send private message

Why does 0 != 0?
PostPosted: Tue Mar 04, 2008 8:49 pm     Reply with quote

Code:

#include  <16F627A.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_B2, rcv=PIN_B1)

void main(void)
{
        int1 a;
        int1 b;

        a=0;
        b=0;

        if (a != b)
                printf("0 != 0\r\n");
        else
                printf("0 == 0\r\n");

        while(1);
}


When run, this code prints "0 != 0".

What am I failing to understand?

PCM compiler version 4.049;8/6/2007 under linux.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 9:08 pm     Reply with quote

The windows command line version of 4.049 works OK. It displays:
Quote:
0 == 0
epv



Joined: 23 Feb 2008
Posts: 8

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 11:26 pm     Reply with quote

here's the code it generates for the comparison:

Code:

....................         a=0;
002D:  BCF    21.0
....................         b=0;
002E:  BCF    21.1
....................
....................         if (a != b)
002F:  MOVLW  00
0030:  BTFSC  21.0
0031:  MOVLW  01
0032:  MOVWF  22
0033:  BTFSC  00.0
0034:  GOTO   037     // printf("0 != 0")
0035:  BTFSC  00.0
0036:  GOTO   045     // printf("0 == 0")



If the variables are int8 instead, it works fine, and generates the following:

Code:

002F:  MOVF   22,W
0030:  SUBWF  21,W
0031:  BTFSC  03.2
0032:  GOTO   041
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group