Jump to content
Sign in to follow this  
davidb

Problem With Signed Short Type On 18Fxxxx

Recommended Posts

Hi,

 

Problem: The following simply test code demonstrates the problem using

signed data types and the comparison if (error > limit).

 

Expected Behaviour: To work correctly x should be 1 less than y at the end

of the comparison loop.

 

If the code is compiled for a 16F887 then all works as expected with

error defined as any data type; signed char, signed short or signed long.

 

If the code is compiled for a 18F4520 then it fails if error is a signed short

but works correctly for signed char and signed long.

 

It also works correctly if the limit definition is changed to any signed data type.

 

#include <system.h>
static signed short error = -60;
static unsigned char x;
static unsigned char y;
#define limit -50
//signed short limit = -50;

void main()
{
for (error = -60; error < 60; error++)
{
 if (error > limit) //Fails
 {
  x++;
 }

 if (error >= limit) //O.K.
 {
  y++;
 }
}
for (;;
}

 

IDE: MPLAB V8.83

Compiler: SourceBoost C V7.05.1

Targets: PIC16F887, PIC18F4520

Reproducible: 100%

OS: XP Pro, Vista

 

Regards

 

davidb

Share this post


Link to post
Share on other sites

davidb,

 

Hi,

 

Problem: The following simply test code demonstrates the problem using

signed data types and the comparison if (error > limit).

 

Expected Behaviour: To work correctly x should be 1 less than y at the end

of the comparison loop.

This is definitely a problem.

Thanks for reporting it.

 

Regards

Dave

Share this post


Link to post
Share on other sites

I have also had problems with comparisons between Interger and constants.

 

My results show a pattern that only a few combinations of small negative constants (8 bit) there are problems with.

 

if(SignInt >= -20)
if(SignInt >  -21)   // Error //

if(SignInt <= -20)   // Error //
if(SignInt <  -19)

if(SignInt <= 20)
if(SignInt <  21)

if(SignInt >= 20)
if(SignInt >  19)

if(SignInt >= -300)
if(SignInt >  -301)

if(SignInt <= -300)
if(SignInt <  -299)

if(SignInt <= 300)
if(SignInt <  301)

if(SignInt >= 300)
if(SignInt >  299)

 

When can we expect the error to be corrected?

 

BoostC Compiler Version 7.03 for PIC18, MPLAB v8.63, Win7 Pro 64

Share this post


Link to post
Share on other sites
Was this problem supposed to have been fixed in V7.1?

 

No this problem is not fixed yet :(

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum 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  

×