C90 不允许在 printf 中使用 %lf,为什么?

标签 c

我是一名初学编程的学生,只是想了解这背后的原因。

当我使用这段代码时:

#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/

相关文章:

c - 从链接列表中释放和删除重复项?

c - 如何释放指向保存地址的指针的指针

c - 调用者看不到函数中的变量更改?

c++ - 记事本显示 Unicode 字符,因为文件是 ANSI?

c - 我对链表有一些问题

使用平行边更改字符串位置中的字符值,例如 yuv = vuy

c++ - 为什么通过 ***char 传递给函数的 nullptr 终止数组会丢失终止元素?

c - 按位 & 和 I

c - 为什么我的代码会执行我没有编写的作业?

c - 将函数指针分配给变量