I'm a beginner programming student, just wanted to learn the reason behind this.
When I use this code:
#include <stdio.h>
int main()
{
double pi = 3.1415926535897932;
printf("%lf",pi);
return 0;
}
Compiler gives this warning. ISO C90 does not support the ‘%lf’ gnu_printf format [-Wformat]
I use the gcc compiler in ubuntu terminal with (-o -Wall -ansi -pedantic-errors)
What's the reason behind this? I searched web and found this use is allowed in C99. Why C90 didn't allow %lf use in printf? I can use %.16lf or %.16f and both print with the same precision, so what's the matter that makes %lf bad in C90?
%lli or %lld. Long long. %llu. Unsigned long long.
Type conversion specifier. The type conversion specifier character specifies whether to interpret the corresponding argument as a character, a string, a pointer, an integer, or a floating-point number. The type character is the only required conversion specification field, and it appears after any optional fields.
PRIu64 is a string (literal), for example the following: printf("%s\n", PRIu64); prints llu on my machine. Adjacent string literals are concatenated, from section 6.4.
According to C90 documentation:
an optional l (ell) specifying that a following d , i , o , u , x , or X conversion specifier applies to a long int or unsigned long int argument; an optional l specifying that a following n conversion specifier applies to a pointer to a long int argument; or an optional L specifying that a following e , E , f , g , or G conversion specifier applies to a long double argument. If an h , l , or L appears with any other conversion specifier, the behavior is undefined.
C is an evolving language. New features and behaviors get added in every new release of the C standard.
C89 says that l
before f
leads to undefined behavior. And C90 probably says the same.
C99 on the other hand says that l
before f
has no effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With