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
  • You're thinking of the %lf conversion in scanf() for a double which doesn't exist in printf().

    No. I was thinking of exactly what I wrote: that the 'h' modifier doesn't exist at all, for floating-point, neither in printf() nor in scanf().

    Compilers are not required to, and generally do not, parse the format string.

    Quite a number of compilers do parse it, if they can see it. GCC, e.g., does. And IMHO such checks are even more important to be done by a compiler for embedded systems, like C51, where the runtime library has essentially no sane way of signalling a runtime error.

Reply
  • You're thinking of the %lf conversion in scanf() for a double which doesn't exist in printf().

    No. I was thinking of exactly what I wrote: that the 'h' modifier doesn't exist at all, for floating-point, neither in printf() nor in scanf().

    Compilers are not required to, and generally do not, parse the format string.

    Quite a number of compilers do parse it, if they can see it. GCC, e.g., does. And IMHO such checks are even more important to be done by a compiler for embedded systems, like C51, where the runtime library has essentially no sane way of signalling a runtime error.

Children
No data