public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/31470] New: inttypes.h provides incorrect macro definitions
@ 2024-03-11  1:05 luigighiron at gmail dot com
  2024-03-11 12:43 ` [Bug libc/31470] " fweimer at redhat dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: luigighiron at gmail dot com @ 2024-03-11  1:05 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=31470

            Bug ID: 31470
           Summary: inttypes.h provides incorrect macro definitions
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: luigighiron at gmail dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

The inttypes.h header provides macros for printing out the types defined in
inttypes.h and stdint.h. In C23, the following text was added to the C standard
in section 7.8.1 "Macros for format specifiers":

> The functions in the fprintf and fwprintf families shall behave as if they use
> va_arg with a type argument naming the type resulting from applying the
> default argument promotions to the type corresponding to the macro and then
> convert the result of the va_arg expansion to the type corresponding to the
> macro.

For example:

#include<stdio.h>
#include<inttypes.h>
int main(){
    uint8_t u=-1;
    printf("%"PRIu8"\n",u+1);
}

This program should output 0, at least in C23. u contains the value 255, then
one is added which results in the value 256 (after integer promotions). 256 is
provided to printf which will do va_arg with int (the promoted type of uint8_t)
and that value is then converted back to uint8_t which will result in the value
0.

However, libc (I tested it on godbolt) seems to print 256 here because it does
not do the conversion back to uint8_t. This seems to be because libc defines
PRIu8 here as "u". I tested this on MSVC and Cygwin and it printed 0 as
expected, with those compilers it is defined as "hhu". The text which requires
that the conversion back after va_arg was added by GB-108 (N3148). See N3167
for discussion about accepting GB-108.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-11 15:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11  1:05 [Bug libc/31470] New: inttypes.h provides incorrect macro definitions luigighiron at gmail dot com
2024-03-11 12:43 ` [Bug libc/31470] " fweimer at redhat dot com
2024-03-11 13:12 ` schwab@linux-m68k.org
2024-03-11 14:44 ` luigighiron at gmail dot com
2024-03-11 15:25 ` schwab@linux-m68k.org
2024-03-11 15:34 ` jsm28 at gcc dot gnu.org
2024-03-11 15:36 ` jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).