Reputation: 305
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?
Upvotes: 12
Views: 9583
Reputation: 62068
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.
Upvotes: 5
Reputation: 6563
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.
Upvotes: 8