This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Regression with printf 8-bit format macros



On 01/04/2016 02:16 PM, Ambroz Bizjak wrote:
Hi Craig, others,

The quoted part of the standard does explain how "hh" shall behave,
but I do not see any implication that PRI*N should use hh or generally
that the described conversion (after promotion) is required for PRI*N.
(note: I suspect you meant to use PRIu8 in the example not PRId8
because the conversion of 1000 to int8_t is an integer overflow.)
Yes, it is implied, by the "suitable for use within the format argument of a formatted input/output function when converting the corresponding integer type" clause. Not only that, the very existence of the macros implies it. Why would you bother with ""%"PRId*" rather than just using "%d"? You use the macro to supply the correct modifier that you would use if you knew the type (and that the type were invariant). If the macros never supplied modifiers, then they'd be useless. I copied the example directly from the opening email, which used d. I should have said that -24 should be printed--the signed interpretation of 0xE8--rather than 232. (I used an unsigned method of giving myself the decimal initially. 1000=0x3E8, which will be passed as that (assuming ints are >=16 bits), then the cast to signed char truncates to 0xE8, is either 232 or -24.)

About the %n issue, it has no relation to the PRI* macros. The PRI*
macros cannot possibly used together with "n", because each PRI* macro
must end with a conversion specifier, which is not "n", and there can
only be one conversion specifier in a conversion. For example,
"%n"PRId8 and "%"PRId8"n" could become "%nd" and "%dn" respectively
(the first one writes out the position then prints a literal d, the
second prints a integer and a literal n). Notice that the standard
does not define any "PRIn..." macro.
My bad on that, I failed to check the list properly for PRIn... . (I guess I shouldn't rush so much next time. Sorry for the noise.)

Best regards,
Ambroz




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]