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

Bitfield compares with int ... Compiler bug ?

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







Bitfield compares with int ... Compiler bug ?
PostPosted: Tue Feb 20, 2007 1:41 pm     Reply with quote

Hello,

I have a program running on PIC18F2585 which I always compiled with V 3.236. It works well.

When I wanted to change PIC to 18F2682, I tried to compile the code with v4.023 and it did not work any more. So I switch back to the last 'stable' version of the compiler V3.249, but it still did ot work.

Digging in the assembly code and with the help of my ICD debugger, I found some strange behaviour of the compiler when comparing bitfield with int. Here is a snipset of the listing code, obtained with V3.236 (working) and V4.023 (not working).

(m is a pointer to a struct with a member named eid, also a struct, containing bitfield filhit)

1) Working code (V3.236)
Code:
....................       if (m->eid.filhit == 2 || m->eid.filhit == 3) checkMsgCanConfig(m);       
44FE:  MOVLW  01
4500:  MOVLB  7
4502:  ADDWF  x68,W
4504:  MOVWF  FE9
4506:  MOVLW  00
4508:  ADDWFC x69,W
450A:  MOVWF  FEA
450C:  MOVFF  FEF,00
4510:  RRCF   00,F
4512:  RRCF   00,W
4514:  ANDLW  07
4516:  SUBLW  02     <-- OK compare with 2
4518:  BZ    4534
451A:  MOVLW  01
451C:  ADDWF  x68,W
451E:  MOVWF  FE9
4520:  MOVLW  00
4522:  ADDWFC x69,W
4524:  MOVWF  FEA
4526:  MOVFF  FEF,00
452A:  RRCF   00,F
452C:  RRCF   00,W
452E:  ANDLW  07
4530:  SUBLW  03       <-- OK compare with 3
4532:  BNZ   4542
4534:  MOVFF  769,802
4538:  MOVFF  768,801
453C:  MOVLB  0
453E:  GOTO   37B6


2) Not working code (v4.023 / v3.249)
Code:
....................       if (m->eid.filhit == 2 || m->eid.filhit == 3) checkMsgCanConfig(m);       
48A2:  MOVLW  01
48A4:  MOVLB  7
48A6:  ADDWF  x68,W
48A8:  MOVWF  FE9
48AA:  MOVLW  00
48AC:  ADDWFC x69,W
48AE:  MOVWF  FEA
48B0:  MOVFF  FEF,00
48B4:  RRCF   00,F
48B6:  RRCF   00,W
48B8:  ANDLW  07
     ---------------------------------> Code Missing
48BA:  BZ    48D4
48BC:  MOVLW  01
48BE:  ADDWF  x68,W
48C0:  MOVWF  FE9
48C2:  MOVLW  00
48C4:  ADDWFC x69,W
48C6:  MOVWF  FEA
48C8:  MOVFF  FEF,00
48CC:  RRCF   00,F
48CE:  RRCF   00,W
48D0:  ANDLW  07
     ---------------------------------> Code Missing
48D2:  BNZ   48E2
48D4:  MOVFF  769,803
48D8:  MOVFF  768,802
48DC:  MOVLB  0
48DE:  GOTO   3B5C


I finally found a workaround, the following code works:
Code:
....................       if ((int8)m->eid.filhit == 2 || (int8)m->eid.filhit == 3)


Is this a compiler bug or am I missing something with my knowledge of C ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 4:52 pm     Reply with quote

I can't find the posts right now, but it sometimes happens that in CCS
you have to "help" the compiler by casting a complex expression to
the correct data type. I recall some post where this involved structure
access operations.
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