Menu

#3644 mcs51: implicit promotion of 8-bit -> 16-bit in variadic args not working

closed-wont-fix
None
MCS51
5
2023-09-11
2023-09-11
Oleg Endo
No

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

Discussion

  • Maarten Brock

    Maarten Brock - 2023-09-11
    • status: open --> closed-wont-fix
    • assigned_to: Maarten Brock
     
  • Maarten Brock

    Maarten Brock - 2023-09-11

    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.

     
    • Philipp Klaus Krause

      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.

       
  • Oleg Endo

    Oleg Endo - 2023-09-11

    Thanks for the clarification!

     

Log in to post a comment.