compiling the following example with --model-large --std-sdcc2x -mmcs51 --stack-auto --nogcse
int main (void)
{
printf ("bleh = %04x\n", (uint8_t)0xA3);
}
prints
bleh = a3c0
the expected output is
bleh = 00a3
rewriting the program as follows yields the expected result:
int main (void)
{
uint8_t bleh = (uint8_t)0xA3;
printf ("bleh = %04x\n", bleh);
}
SDCC version: 4.3.2 #0 (Linux) SVN r14340
This is deliberate. Using an explicit cast tells the compiler not to mess with promotions and pass the value as a single byte. This can be used with "%bc". You can add a second cast to int to get the expected result.
For details see section 3.5.12, "Omitting promotion on arguments of vararg function (does not apply to pdk13, pdk14, pdk15)" in the manual.
Having just had a look at it, that section could be a bit clearer though, as
--std-sdccxx
is the default.Thanks for the clarification!