Comparison Always True Problem

Help
2010-01-27
2013-03-12
  • Hello,

       I am using SDCC for an 8051embedded in an FPGA.  I have some code which used to work on Keil, but can't get it working on SDCC.
       I want to be able to Peek and Poke at custom SFR registers.  I get the following warning:

    TestUtility.c:215: warning 94: comparison is always true resp. false due to limited range of data type
    TestUtility.c:215: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG

       This prevents my subroutine from working.  I am just trying to take a value from the COM port, and use that as the SFR address.

    // Provides ability to read from external addresss via COM port interaction
    void PokeSFR(void)
    {
      unsigned char address;
      unsigned char val;

      DEBUG_Print("\n\rAddress> ");
      address = DEBUG_GetHex();  
      DEBUG_Print("\n\rData> ");
      val = DEBUG_GetHex();
      switch(address)
      {
      case 0x91 : SPWSTATUS         = val;   break;
      case 0x95 : SPWRXDATAVALID    = val;   break;
      case 0x96 : SPWEXPVALID       = val;   break;
      <snip>
      default:  DEBUG_Print("Unrecognized SFR"); break;
      }
    }

      Any thoughts on how to remove the warnings, or better yet to get the case statement working?

    Thanks,
    Pat

     
  • which of the source line you have given is line 215?

    TestUtility.c:215: warning 94: comparison is always true resp. false due to limited range of data type

    (could be you test an unsigned type for >=0  or <0 there)

     
  • Frief,

      Thank you for your reply.
      Line 215 corresponds to :
     
      switch(address)

      Below are the other relevant modules.  The odd thing is that I use the DEBUG_GetHex function in other routines (such as a Peek to xData space) without any problems. 

    /////////////////
    typedef unsigned char BYTE;
    BYTE HexTable = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

    // Waits for two characters from serial port, converts from hex string to a byte
    // Echos what is received.  Feeds Watch Dog Timer while servicing to avoid reboot.
    unsigned char DEBUG_GetHex(void)
    {
      volatile BYTE val, xval, i;

      while(!mygetchar(&xval))
      {
      FeedWDT();
      };
      if(xval>=0x61 && xval<=0x66) xval-=0x20;
      myputchar(&xval);
      val=0;
      for(i=0;i<16;i++) if(xval==HexTable_) val = i*0x10;
      while(!mygetchar(&xval))
      {
      FeedWDT();
      };
      if(xval>=0x61 && xval<=0x66) xval-=0x20;
      myputchar(&xval);
      for(i=0;i<16;i++) if(xval==HexTable) val += i;

      return(val);
    }

    BYTE mygetchar(BYTE *RXByte)
    {
      if (UART0NUMBYTESRX == 0)
        return 0;

      *RXByte = UART0RX;
      return 1;
    }

    ///////////////////

    Regards,
    Pat
    _

     
  • Hi Pat,

    I added a some lines to make it compile and cannot reproduce the warning with:
    SDCC 2.9.5 #5614 (Jan  4 2010) (UNIX)

    file sdcc-help_2010-01-27.c :
    -8<-------------------
    #include <8052.h>

    #define UART0RX RXD

    typedef unsigned char BYTE;

    BYTE UART0NUMBYTESRX;
    const BYTE __code HexTable = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

    extern void myputchar(BYTE *RXByte);
    extern void FeedWDT();
    extern void DEBUG_Print(const unsigned char __code *p);

    __sfr __at(0x91) SPWSTATUS;
    __sfr __at(0x95) SPWRXDATAVALID;
    __sfr __at(0x96) SPWEXPVALID;

    BYTE mygetchar(BYTE *RXByte)
    {
      if (UART0NUMBYTESRX == 0)
        return 0;

      *RXByte = UART0RX;
      return 1;
    }

    // Waits for two characters from serial port, converts from hex string to a byte
    // Echos what is received.  Feeds Watch Dog Timer while servicing to avoid reboot.
    unsigned char DEBUG_GetHex(void)
    {
      volatile BYTE val, xval, i;

      while(!mygetchar(&xval))
      {
              FeedWDT();
      };
      if(xval>=0x61 && xval<=0x66) xval-=0x20;
      myputchar(&xval);
      val=0;
      for(i=0;i<16;i++) if(xval==HexTable_) val = i*0x10;
      while(!mygetchar(&xval))
      {
              FeedWDT();
      };;
      ;;;; // ;)
      if(xval>=0x61 && xval<=0x66) xval-=0x20;
      myputchar(&xval);
      for(i=0;i<16;i++) if(xval==HexTable) val += i;

      return(val);
    }

    // Provides ability to read from external addresss via COM port interaction
    // note void PokeSFR(unsigned char address, unsigned char val);
    // would improve reusability
    void PokeSFR(void)
    {
      unsigned char address;
      unsigned char val;

      DEBUG_Print("\n\rAddress> ");
      address = DEBUG_GetHex();
      DEBUG_Print("\n\rData> ");
      val = DEBUG_GetHex();
      switch(address)
      {
      case 0x91 : SPWSTATUS         = val;   break;
      case 0x95 : SPWRXDATAVALID    = val;   break;
      case 0x96 : SPWEXPVALID       = val;   break;
    // <snip>
      default:  DEBUG_Print("Unrecognized SFR"); break;
      }
    }
    ->8-------------------_