我是一名初学编程的学生,只是想了解这背后的原因。
当我使用这段代码时:
#include <stdio.h>
int main()
{
double pi = 3.1415926535897932;
printf("%lf",pi);
return 0;
}
编译器发出此警告。 ISO C90 不支持 '%lf' gnu_printf 格式 [-Wformat]
我在带有 (-o -Wall -ansi -pedantic-errors) 的 ubuntu 终端中使用 gcc 编译器
这背后的原因是什么?我在网上搜索,发现 C99 允许这种用法。为什么 C90 不允许在 printf 中使用 %lf?我可以使用 %.16lf 或 %.16f 并且两者都以相同的精度打印,那么是什么原因导致 %lf 在 C90 中不好?
最佳答案
根据 C90 文档:
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.
关于C90 不允许在 printf 中使用 %lf,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15614620/