Why does GCC 11.3.0 generate -Wformat warning on my x86_64 machine, but doesn't on godbolt x86_64 machine?

32 Views Asked by At
$ uname -m
x86_64
$ cat t56.c
#include <stdint.h>
#include <stdio.h>
int main(void)
{
    typedef struct { uint64_t v; } float64_t;
    union { double tf; float64_t f; } uX = {0};
    printf("%a [%lx]", uX.tf, uX.f);
}
$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc t56.c -std=c11
t56.c: In function ‘main’:
t56.c:7:19: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘float64_t’ [-Wformat=]
    7 |     printf("%a [%lx]", uX.tf, uX.f);
      |                 ~~^           ~~~~
      |                   |             |
      |                   |             float64_t
      |                   long unsigned int

Here we see that on my x86_64 machine GCC 11.3.0 generates -Wformat warning.

Let's compile the same code on godbolt x86_64 machine using GCC 11.3.0: https://godbolt.org/z/6hPTdsEb5

There we see that on godbolt x86_64 machine GCC 11.3.0 does not generate -Wformat warning.

Why does GCC 11.3.0 generate -Wformat warning on my x86_64 machine, but doesn't on godbolt x86_64 machine?

Extra question: are GCC 11.3.0 and GCC 11.3 the same versions?

0

There are 0 best solutions below