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
  • My simple question seems indeed to have a non-trivial and non-obvious answer wrt various C implementations. Thank you for the answers.

    (Andrew, Hans: pardon, my ref to short should have indeed been char. In my mind, when working with 8bit i/o registers and small loop counters, I don't think of them as characters, but integers--which I typecast to int8u or int8s.)

    Stefan: regarding the %c, will it correctly handle signed 8bit integers as well?
    In general, I wonder what a good strategy is for handling these instances... for example, is it advisable to cast printf() arguments explicitly? Perhaps there is a big efficiency penalty vs. simply using the appropriate modifier.

Reply
  • My simple question seems indeed to have a non-trivial and non-obvious answer wrt various C implementations. Thank you for the answers.

    (Andrew, Hans: pardon, my ref to short should have indeed been char. In my mind, when working with 8bit i/o registers and small loop counters, I don't think of them as characters, but integers--which I typecast to int8u or int8s.)

    Stefan: regarding the %c, will it correctly handle signed 8bit integers as well?
    In general, I wonder what a good strategy is for handling these instances... for example, is it advisable to cast printf() arguments explicitly? Perhaps there is a big efficiency penalty vs. simply using the appropriate modifier.

Children
No data