From: tr.17687@z991.linuxsc.com   
      
   Keith Thompson writes:   
      
   > David Brown writes:   
   > [...]   
   >   
   >> C23 includes length specifiers with explicit bit counts, so "%w32u" is   
   >> for an unsigned integer argument of 32 bits:   
   >>   
   >> """   
   >> wN Specifies that a following b, B, d, i, o, u, x, or X conversion   
   >> specifier applies to an integer argument with a specific width   
   >> where N is a positive decimal integer with no leading zeros   
   >> (the argument will have been promoted according to the integer   
   >> promotions, but its value shall be converted to the unpromoted   
   >> type); or that a following n conversion specifier applies to a   
   >> pointer to an integer type argument with a width of N bits. All   
   >> minimum-width integer types (7.22.1.2) and exact-width integer   
   >> types (7.22.1.1) defined in the header shall be   
   >> supported. Other supported values of N are implementation-defined.   
   >> """   
   >>   
   >> That looks to me that it would be a correct specifier for uint32_t,   
   >   
   > Yes, so for example this:   
   >   
   > uint32_t n = 42;   
   > printf("n = %w32u\n", n);   
   >   
   > is correct, if I'm reading it correctly. It's also correct for   
   > uint_least32_t, which is expected to be the same type as uint32_t   
   > if the latter exists. There's also support for the [u]int_fastN_t   
   > types, using for example "%wf32u" in place of "%w32u".   
   >   
   >> and should also be fully defined behaviour for unsigned int and   
   >> unsigned long if these are 32 bits wide.   
   >   
   > No, I don't think C23 says that.   
      
   Right, it doesn't.   
      
   > If int and long happen to be the same   
   > width, they are still incompatible, and there is no printf format   
   > specifier that has defined behavior for both.   
   >   
   > That first sentence is a bit ambiguous   
   >   
   > wN Specifies that a following b, B, d, i, o, u, x, or X conversion   
   > specifier applies to an integer argument with a specific width ...   
   >   
   > but I don't think it means that it must accept *any* integer type   
   > of the specified width.   
      
   As I read the standard there is no ambiguity. The first sentence   
   says what the length modifier means. The second sentence says   
   which types (if any) correspond to the description in the first   
   sentence.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|