------------------------------------------- #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!
The message is really quite explicit. It is telling you that sprintf() expects its first argument to be a pointer to a signed type, not an unsigned type. See: http://www.keil.com/support/man/docs/c51/c51_sprintf.htm To remove the error, change lcd_show_buf to be a char array (i.e., drop the unsigned) or in the sprintf() invocation, cast lcd_show_buf (e.g., (char *)lcd_show_buf).
Thank u ,Dan Henry I adopt the means of casting lcd_show_buf( (char *)lcd_show_buf ) you just suggested and have removed the pc-lint error successfully. I just find guys here warmhearted.Thank u!
It's worth pointing out another couple of things: sprintf(lcd_show_buf, "%4d", num); Should really be "%4u" as num is unsigned. Also, this line is ok if you have ANSI integer promotion enabled, if you disable it you would need "%4bu" instead. I can't think of any reason why anyone would use ANSI integer promotion other than to maintain ANSI compatibility as it increases code space usage and execution time. Stefan
to Stefan: 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. The compiler information I used now follows here: IDE-Version: uVision2 V2.23 Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2002 License Information: lizongqi Lee xgxc Serial Number: XXXXX-XXXXX-XXXXX Support End: Mar 2016 Tool Version Numbers: Toolchain Path: C:\Program Files\keil\C51\BIN\ C Compiler: C51.exe V6.23a Assembler: A51.exe V6.23 Linker/Locator: BL51.exe V4.23 Librarian: LIB51.exe V4.23 Hex Converter: OH51.exe V2.6 Simulation DLL: S8051.DLL V2.23 Dialog DLL: DP51.DLL V2.23g I can't find where the problem is. P.S. My written Enlish is poor. I'm sorry that the meaning I just expressed may be puzzled you.
Thank u!
"I didn't find the ANSI integer promotion switch" It's on the 'C51' tab in the uVision Project Options - on the right-hand side, just above the 'Include Paths' box. See p80 in the uVision Getting Started guide (02.2001 version). BTW: As you have support until March 2016(!!), why not upgrade to the current version?
to Andy Neil: Oh yes, I find it!Thank u for your detailed reply! Any latest version of certain software,as you know ,will have serval buggs hidden it.Some of them may be vital. I just wait for it until it is relatively perfect. Thank u ,any way. Thank u ,all . ^_^
"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