This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

why get error "Type mismatch (arg. no. 1) (ptrs to signed/unsigned)"?

-------------------------------------------
#define uchar unsigned char

uchar xdata lcd_show_buf[20];
uchar num;

num = 2;

sprintf(lcd_show_buf, "%4d", num);

-------------------------------------------
use pc-lint , get the following error:

Error 64: Type mismatch (arg. no. 1) (ptrs to signed/unsigned)

I just want to know how to avoid such errors?
Thank u!

Parents
  • "As you just suggested,I changed the following code.
    //unsigned int num

    //older version
    sprintf((char *)lcd_show_buf, "%4d", num);

    //latest version
    sprintf((char *)lcd_show_buf, "%4u", num);

    I didn't find the ANSI integer promotion switch you said. I just find the latest version occupy more code space, 41177B to 41181B."

    I didn't mean you should make num an int. The idea is this:

    unsigned char num=5;

    sprintf((char *)lcd_show_buf,"%4bu",num);

    The above should produce the tightest code provided ANSI integer promotion is turned off. It will not work properly if it is turned on. By doing the above you can maintain num as a single byte variable *and* avoid it being converted to a 2 byte int during the call to sprintf(), hence less code.

    Stefan

Reply
  • "As you just suggested,I changed the following code.
    //unsigned int num

    //older version
    sprintf((char *)lcd_show_buf, "%4d", num);

    //latest version
    sprintf((char *)lcd_show_buf, "%4u", num);

    I didn't find the ANSI integer promotion switch you said. I just find the latest version occupy more code space, 41177B to 41181B."

    I didn't mean you should make num an int. The idea is this:

    unsigned char num=5;

    sprintf((char *)lcd_show_buf,"%4bu",num);

    The above should produce the tightest code provided ANSI integer promotion is turned off. It will not work properly if it is turned on. By doing the above you can maintain num as a single byte variable *and* avoid it being converted to a 2 byte int during the call to sprintf(), hence less code.

    Stefan

Children
No data