Jump to content
teunizz

Bug In Type "unsigned Long"

Recommended Posts

Bug description:

A variable declared as unsigned long, can not contain values higher than 2147483647.

 

Steps to reproduce:

 

Compile the following code for a PIC18F4620 and run it in the debugger,

at the same time watch the variable "var".

 

#include <system.h>


void main()
{
 unsigned long var;

 var = 2147483648;

 while(1);
}

 

Expected behaviour:

A variable declared as unsigned long should be able to contain values in the range

of 0 ~ 4294967295.

 

Is the problem 100% reproduceable:

Yes, this problem is 100% reproducable.

 

IDE version: SourceBoost 6.60

Compiler: BoostC

Compiler version: 6.60

Target device: PIC18F4620

OS: Windows XP

 

Comments:

I hope this will be patched soon instead of waiting for a newer version.

 

Regards,

Teuniz

Share this post


Link to post
Share on other sites

teunizz,

Bug description:

A variable declared as unsigned long, can not contain values higher than 2147483647.

I just checked this. The variable can contain > 2147483647, but the problem is it can be initialised with a constant value > 2147483647.

 

So a work around is to add on the extra that exceeds 2147483647.

void main()
{
   unsigned long x = 2147483647;
   x += 5000;
}

 

Regards

Dave

Share this post


Link to post
Share on other sites
//
// File: bug13.C
// Target: PIC16F648A
// OS: WinXP, SP2
// SourceBoostIDE: 6.60
// Compiler: BoostC 6.60
// Reproducible: always
// Expected behavior: compile with warning or error.
//
// Description: 
//
//  Constant value calculated by compiler has overflowed.
//  This should cause some kind of notification.
//  
#include <system.h>

volatile unsigned long v;
volatile short i;
volatile unsigned short u;
volatile signed char a;
volatile unsigned char b;

void main()
{
 v = 2147483647 + 2147483647 + 2;
 i = 32767 + 32767 + 2;
 u = 65535 + 1;
 a = 127 + 127 + 2;
 b = 255 + 1;

main_loop:
 while(v);
 if (v==0) goto main_loop;
}

Share this post


Link to post
Share on other sites

Cause of the problem found and fixed. Fix will be available in the next release. A workaroung for the current release is to use constants in HEX format (octal and binary will work as well :) ) i.e.:

 

unsigned long x = 0x80000000;

unsigned long y = 020000000000;

unsigned long z = 0b10000000000000000000000000000000;

 

Regards,

Pavel

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...

×
×
  • Create New...