From: Kevin V. <ke...@vi...> - 2001-01-25 00:01:15
|
On 24-Jan-2001 Scott Hughes wrote: > Thanks for the feedback about the pointer to the sfr. Guess I'm stuck But I'm seeing some pretty strange > behaviour > from printf. With the following code: > printf("%01X\r\n",0x0f); SDCC is passing the constant parameter 0x0f as a single byte; the %X format specifier wants an int argument. This may be a bug (I'm not sure offhand if the constant should be promoted to int), but in the meantime, you should be able to work around it either by typecasting the constant to int, or by using the 'b' modifier in your printf format string (btw, I believe this is non-standard and should be changed to 'h', which is standard, someday), like so: printf("%01bX\r\n",0x0f); (I am not near a working TINI, so I can't actually test this right now). > one test program from the 1-Wire api, I have a string that I know to be > valid and it can be printed fine with puts(char*). But use that same > string > with printf("%s",char*) and it hangs the tini. Probably a similar problem: the %s printf conversion expects a generic pointer to char. The following code will blow up: char _xdata *str; printf("%s",str); (quite apart from the fact that str is uninitialized) because str is passed to printf as an xdata * rather than a generic *. Because puts() has a proper prototype instead of a varargs ..., the compiler can do the proper conversions for you (if necessary). The only workaround for this one is an explicit typecast: char _xdata *str; printf("%s",(char _generic *)str); Take-home lesson here: varargs functions (like printf) are weird, and SDCC probably doesn't follow all the rules for argument promotion properly. Peace, Kevin |