Thi est confirmée également dans printf (3) manpage:C99 standard et gnu libc printf
L
A suivant un, A, e, E, f, F, g, ou g conversion correspond à un long double argument.
Si je compile ceci:
printf("%Ld",3);
utilisant std = c99 argument de gcc, je reçois un avertissement:
warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
printf("%Ld",3);
^
Il semble que gnu libc ne folloe pas standard c99
Je gcc 6.3.0, gnu libc 2,24, mon hôte est un linux ubuntu 17.04 64bit
[Modifié]
si je compilez ceci:
printf("%Ld\n",3);
printf("%lld\n", 3LL);
printf("%Lf\n", 3.3L);
printf("%llf\n", 3.3L);
printf("%f\n", 3.3L);
Je reçois:
warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
printf("%Ld\n",3);
^
warning: use of ‘ll’ length modifier with ‘f’ type character has either no effect or undefined behavior [-Wformat=]
printf("%llf\n", 3.3L);
^
warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
printf("%f\n", 3.3L);
^
Ainsi, le message d'avertissement est attendu comme pour %llf
.
avec -pedantic je reçois des messages plus verbeux:
warning: ISO C does not support the ‘%Ld’ gnu_printf format [-Wformat=]
printf("%Ld\n",3);
^
warning: format ‘%Ld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
warning: use of ‘ll’ length modifier with ‘f’ type character has either no effect or undefined behavior [-Wformat=]
printf("%llf\n", 3.3L);
^
warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
printf("%f\n", 3.3L);
^
[Edité]
J'ai un mail from gcc ML
il semble que '% Ld' est autorisé et nécessitent 'long long int'.
Mais c'est autorisé par GNU libc, c'est le point. Pour GNU libc% Ld signifie la même chose que% LLD, mais c'est non-standard, lorsque vous utilisez -pedantic vous obtenez un avertissement.
Et cela explique le message d'avertissement.
Il semble que votre code ne respecte pas la norme. Qu'attendiez-vous de% Ld? – Sneftel
@Sneftel C'est toujours une question intéressante. Le réchauffement est trompeur, je dirais. Et je me demande ce que la sortie avec '-pedantic' est. –
@Sneftel - '% Ld' n'est pas couvert par la norme, et son comportement est indéfini. Dans un code source je l'ai écrit accidentellement, et l'avertissement gcc m'a semblé étrange @AndrewHenle - J'ai ajouté le '-pedantic'output à la poste orifinal – mastupristi