Jump to content

Compile Error For "unsigned Long R;"

Recommended Posts

  File: bug20.C
  Target: PIC16F876A
  OS: WinXP, SP2
  SourceBoostIDE: 6.70
  Compiler: BoostC 6.70
  Reproducible: always
  Expected behavior: compile without error

  Statement: "unsigned long R;" results in "C:\Public\SourceBoost\bugs\bug20.c(58): error:  failure".
  If target is PIC16F684 then compiles without error.

  PIC16F876A and PIC16F684 are the only targets that have been tried.
#include <system.h>

unsigned char div64by32(unsigned long &Quotient, unsigned long &Remainder, unsigned long DividenHI, unsigned long DividenLOW, unsigned long Divisor)

  unsigned char count;
  // do a 64-bit divided by 32-bit integer division
  count = 64;
  Remainder = 0;
  Quotient  = DividenLOW;
  // do not divide by zero
  if (Divisor)
          Remainder = (Remainder << 1) | (DividenHI.31);
          DividenHI = (DividenHI << 1) | (Quotient.31);
          Quotient = (Quotient << 1);
          if (Remainder >= Divisor)
              Remainder -= Divisor;
              Quotient |= 1;
      } while (--count);
  if (0 == DividenHI)
      return (0); // Division valid
      // divide overflow, Divisor too small for
      // result to fit in to a 32-bit value.
      return (1); // Division overflow

unsigned long Q;
unsigned long R;
unsigned char result;

void main()

 result = div64by32(Q,R,0x7FFFffff,0xFFFFffff,0xFFFFffff);


Edited by cac001
Link to post
Share on other sites
  • 4 months later...

There is no compiler error here. For number of targets (like 16F687 R is used as a define in system.h). Preprocessor replaces your declaration directive with something that looks like 'unsigned long 0x0002;' and that's why you see this error.




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.

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.

  • Create New...