This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: misleading warning message
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: massimiliano cialdi <massimiliano dot cialdi at powersoft dot it>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 8 Jun 2017 10:03:58 +0100
- Subject: Re: misleading warning message
- Authentication-results: sourceware.org; auth=none
- References: <7be5d5d6-4043-1f8c-b240-a80604dcb74d@powersoft.it>
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."