Mike Hommey | 11 Apr 12:10 2012

-Wformat and %llu

Hi,

I recently downloaded mingw-w64-gcc-4.6.3-runtime-2.0.1-static-ada-20120321.7z
and when compiling some things with it, I end up with unexpected warnings for
format strings. The problem can be reproduced with the following:

---->8-----
#include <stdio.h>
int main() {
  size_t a = 1;
  printf("%llu %llu\n", a, sizeof(a));
  return 0;
}
-----8<----

$ x86_64-w64-mingw32-gcc -o test test.c -Wall
test.c: In function 'main':
test.c:4:1: warning: unknown conversion type character 'l' in format [-Wformat]
test.c:4:1: warning: unknown conversion type character 'l' in format [-Wformat]
test.c:4:1: warning: too many arguments for format [-Wformat-extra-args]

The resulting binary however works just fine.

Sure, I could use %Iu, but it's less portable: with %llu, I only have to care
about 32 vs 64 bits size_t...

Mike

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
(Continue reading)

Kai Tietz | 14 Apr 10:37 2012

Re: -Wformat and %llu

Hi Mike,

the issue is that formatter-width specifier %ll isn't supported for
all msvcrt-DLL versions, therefore gcc warns about its use.  The
variant for specifying 64-bit integer-scalar-width in formatter for
msvcrt in a backward-compatible way is by using %I64.

Regards,
Kai

2012/4/11 Mike Hommey <mh@...>:
> Hi,
>
> I recently downloaded mingw-w64-gcc-4.6.3-runtime-2.0.1-static-ada-20120321.7z
> and when compiling some things with it, I end up with unexpected warnings for
> format strings. The problem can be reproduced with the following:
>
> ---->8-----
> #include <stdio.h>
> int main() {
>  size_t a = 1;
>  printf("%llu %llu\n", a, sizeof(a));
>  return 0;
> }
> -----8<----
>
> $ x86_64-w64-mingw32-gcc -o test test.c -Wall
> test.c: In function 'main':
> test.c:4:1: warning: unknown conversion type character 'l' in format [-Wformat]
> test.c:4:1: warning: unknown conversion type character 'l' in format [-Wformat]
(Continue reading)

JonY | 14 Apr 10:42 2012
Picon
Picon

Re: -Wformat and %llu

On 4/11/2012 18:10, Mike Hommey wrote:
> Hi,
> 
> I recently downloaded mingw-w64-gcc-4.6.3-runtime-2.0.1-static-ada-20120321.7z
> and when compiling some things with it, I end up with unexpected warnings for
> format strings. The problem can be reproduced with the following:
> 
> ---->8-----
> #include <stdio.h>
> int main() {
>   size_t a = 1;
>   printf("%llu %llu\n", a, sizeof(a));
>   return 0;
> }
> -----8<----
> 
> $ x86_64-w64-mingw32-gcc -o test test.c -Wall
> test.c: In function 'main':
> test.c:4:1: warning: unknown conversion type character 'l' in format [-Wformat]
> test.c:4:1: warning: unknown conversion type character 'l' in format [-Wformat]
> test.c:4:1: warning: too many arguments for format [-Wformat-extra-args]
> 
> 
> The resulting binary however works just fine.
> 
> Sure, I could use %Iu, but it's less portable: with %llu, I only have to care
> about 32 vs 64 bits size_t...
> 

Use %I64u on Windows, or just use inttypes.h PRIuMAX.
(Continue reading)


Gmane