Jump to content
Sign in to follow this  
davidb

Signed Short Comparison Fail

Recommended Posts

Hi,

 

SourceBoost 7.2 is still broken in regard to comparing signed data types with #defined constants with 18F parts. This is similar to the >= problem that occured in SourceBoost 7.1. which now seems to be fixed.

 

Problem:

 

The following test code was created to test for the problem. When compiled for 16F, specifically 16F887, it works fine with 'value' as any data type. When compiled for 18F parts, specifically 18F87K22, it works correctly for a signed char or signed long but fails using a signed short in test case 3.

 

Expected Behaviour:

 

To work correctly x should be 1 less than y at the end of the comparison loop for each test case.

 

IDE: MPLAB V8.89
Compiler: SourceBoost C V7.2
Targets: Various 16F, 18F
Reproducible: 100%
OS: XP Pro, Vista

#include <system.h>

static unsigned char x;
static unsigned char y;

static signed short value;
static signed short variable_limit = -10;

#define CONSTANT_LIMIT -10

void main()
{
	for (;
	{
		/* TEST CASE 1 */
		
		x = 0;
		y = 0;
		
		for (value = -20; value < 20; value++)
		{
			if (value > CONSTANT_LIMIT) // Works O.K.
			{
				x++;
			}
		  
			if (value >= CONSTANT_LIMIT) // Works O.K.
			{
				y++;
			}
		}
		
		/* TEST CASE 2 */
		
		x = 0;
		y = 0;
		
		for (value = -20; value < 20; value++)
		{
			if (value > variable_limit) // Works O.K.
			{
				x++;
			}
		  
			if (value >= variable_limit) // Works O.K.
			{
				y++;
			}
		}
			
		/* TEST CASE 3 */
		
		x = 0;
		y = 0;
		
		for (value = 20; value > -20; value--)
		{
			if (value < CONSTANT_LIMIT) // Works O.K.
			{
				x++;
			}
			  
			if (value <= CONSTANT_LIMIT) // Fails with 18F parts
			{
				y++;
			}
		}
		
		/* TEST CASE 4 */
				
		x = 0;
		y = 0;
			
		for (value = 20; value > -20; value--)
		{
			if (value < variable_limit) // Works O.K.
			{
				x++;
			}
			  
			if (value <= variable_limit) // Works O.K.
			{
				y++;
			}
		}
	}	
}

Regards

davidb

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  

×