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

%bu vs. %hu in printf()

I am using simultaneously in the 8bit C51 and 16bit compilers for two related projects.

Am I correct that for 8bit integers,
8-bit compiler uses %bu in printf()
16bit compiler uses %hu
?
Shouldn't they work the same, and accept either modifier?

Thank you.

Parents
  • 16bit compiler uses %hu

    I would rather hope it doesn't. As per the language definition, actually neither of these should need any prefix at all, for printf()ing an 8-bit number. The %b prefix in C51 is there only because C51 doesn't do ANSI default argument promotions. If it did, the prefix wouldn't be needed because, by the time printf() is called, the char would have been silently casted into a 16-bit value.

Reply
  • 16bit compiler uses %hu

    I would rather hope it doesn't. As per the language definition, actually neither of these should need any prefix at all, for printf()ing an 8-bit number. The %b prefix in C51 is there only because C51 doesn't do ANSI default argument promotions. If it did, the prefix wouldn't be needed because, by the time printf() is called, the char would have been silently casted into a 16-bit value.

Children