This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: misleading warning message


On 7 June 2017 at 22:11, massimiliano cialdi  wrote:
> gcc 6.3.0, compile this:
>
> #include <stdio.h>
>
> int main(void)
> {
>     printf("%Ld\n",3L);
>     printf("%llf\n", 3.3L);
>     return 0;
> }
>
> this is the output:
> $ gcc -pedantic -std=c99 -Wall test.c -o test
> test.c: In function ‘main’:
> test.c:5:12: warning: ISO C does not support the ‘%Ld’ gnu_printf format
> [-Wformat=]
>   printf("%Ld\n",3L);
>             ^
> test.c:5:12: warning: format ‘%Ld’ expects argument of type ‘long long int’,
> but argument 2 has type ‘long int’ [-Wformat=]
> test.c:6:13: warning: use of ‘ll’ length modifier with ‘f’ type character
> has either no effect or undefined behavior [-Wformat=]
>   printf("%llf\n", 3.3L);
>              ^
>
> the warning about '%Ld' is misleading. I was expecting something like "use
> of ‘L’ length modifier with ‘d’ type character has either no effect or
> undefined behavior", otherwise it looks that '%Ld' is allowed and require
> ‘long long int’.

But it is allowed by GNU libc, that's the point. For GNU libc %Ld
means the same as %lld, but that's non-standard, so when you use
-pedantic you get a warning.

So it does have an effect, and it isn't undefined.

> also printf(3) manpage says:
>
> *"L:* A following *a*, *A*, *e*, *E*, *f*, *F*, *g*, or *G* conversion
> corresponds to a /long double/ argument."

On my system it also says "This is a synonym for ll."


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