Jump to content
Sign in to follow this  
diaz

Serious order of precedence problem

Recommended Posts

Hello,

 

I believe I have found a rather serious error in the compiler.

 

Bug Description

---------------

Basically it is performing logical OR's before logical AND's and as I understand C's order of precedence

it should happen the other way round.

 

Steps to reproduce

------------------

It was drawn to my attention by some code posted on your examples page:

http://www.picant.com/c2c/examples.html

 

The code is listed as:

This LCD sample application shows how to control HD44780-based character LCD ( by Victor Golutvin):

 

The function LCD_icmd in the file lcdfunc.c contains the line   LCD = data | LCD&0x0F

(Similar lines also exist in the function LCD_cmd)

 

This compiles to:

 

(BTW previously in the main.h file LCD is #defined as equal to "porta")

 

;;;;;;;; porta = data | porta&0x0F ;

bcf STATUS, RP0

bcf STATUS, RP1

movf param00_LCD_icmd, W

iorwf _porta, W

andlw D'15'

movwf _porta

 

Expected behaviour

------------------

Quite obviously this is doing ((data | LCD) & 0x0F) and not (data | (LCD&0x0F)) as it should be.

 

Is the problem 100% reproduceable

---------------------------------

Yes

 

Comments

--------

Fortunately the compiler does take good note of parenthesis so you can force the

correct order of precedence. However in the example in question as it stands

this problem stops the program from outputting anything to porta, so I am presuming

the author of the program compiled it on another version of C2C.

 

P.S. Even after forcing the correct precedence on the problematical lines I

still can't get the program to work. My hardware works fine with another

program. I would be very interested in hearing from anyone that has made Victor

Golutvin's code work.

 

Version Info

------------

PicAntIDE version:   V5.0.5

Compiler:            C2C-plus

Compiler version:    V5.0.5e

OS:                  Windows 98 SE 4.10.2222 A

 

Regards.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...