鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: wyz20010429

[已解决]double,longdouble除了范围的区别

[复制链接]
发表于 2021-8-27 14:25:21 | 显示全部楼层

你的 gcc 不提示,我这边的 gcc 提示说 lf 不对,应该是 Lf
  1. main.c: In function ‘main’:
  2. main.c:10:20: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
  3.    10 |     printf("c=%6.2lf,s=%6.2lf",c,s);
  4.       |               ~~~~~^           ~
  5.       |                    |           |
  6.       |                    double      long double
  7.       |               %6.2Lf
  8. main.c:10:29: warning: format ‘%lf’ expects argument of type ‘double’, but argument 3 has type ‘long double’ [-Wformat=]
  9.    10 |     printf("c=%6.2lf,s=%6.2lf",c,s);
  10.       |                        ~~~~~^    ~
  11.       |                             |    |
  12.       |                             |    long double
  13.       |                             double
  14.       |                        %6.2Lf
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:25:33 | 显示全部楼层
人造人 发表于 2021-8-27 14:03
把 Lf 改成 f 然后
gcc -g -Wall -o main main.c

找到了一个帖子。。但是具体原因我不知道

https://blog.csdn.net/Hippocrates/article/details/104251373
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:26:54 | 显示全部楼层

试试这个
  1. gcc -g -Wall -Wextra -o main main.c
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:29:13 | 显示全部楼层

也是这个
  1. demo.c:10:12: warning: unknown conversion type character 'L' in format [-Wformat=]
  2. demo.c:10:12: warning: too many arguments for format [-Wformat-extra-args]
  3. demo.c:10:12: warning: unknown conversion type character 'L' in format [-Wformat=]
  4. demo.c:10:12: warning: unknown conversion type character 'L' in format [-Wformat=]
  5. demo.c:10:12: warning: too many arguments for format [-Wformat-extra-args]
复制代码



我看到那个帖子说

问题产生原因:
VS Code默认使用了系统crt的printf函数。

这一方面我不太了解,需要再查查资料
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:30:12 | 显示全部楼层
逃兵 发表于 2021-8-27 14:25
找到了一个帖子。。但是具体原因我不知道

https://blog.csdn.net/Hippocrates/article/details/104251 ...

还真是编译器的 bug

在Dev-C++相关头文件中定义long double是12字节,但是Dev-C++的printf却认为long double是8字节,所导致无法正常输出long double类型,这算是Dev-C++的一个BUG。可以尝试换成cout来进行输出。

https://www.zhihu.com/question/64387466/answer/243989049
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:31:19 | 显示全部楼层

把 Lf 改成 f 然后
gcc -g -Wall -Wextra -o main main.c
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:39:48 | 显示全部楼层
人造人 发表于 2021-8-27 14:31
把 Lf 改成 f 然后
gcc -g -Wall -Wextra -o main main.c
  1. demo.c: In function 'main':
  2. demo.c:11:12: warning: format '%f' expects argument of type 'double', but argument 2 has type 'long double' [-Wformat=]
  3.      printf("c=%6.2f,s=%6.2f\n",c,s);
  4.             ^
  5. demo.c:11:12: warning: format '%f' expects argument of type 'double', but argument 3 has type 'long double' [-Wformat=]
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:40:19 | 显示全部楼层
人造人 发表于 2021-8-27 14:30
还真是编译器的 bug

在Dev-C++相关头文件中定义long double是12字节,但是Dev-C++的printf却认为long  ...

谢谢大佬!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-8-27 14:52:40 | 显示全部楼层

没办法了,就是不显示
可能是你的 gcc 太老了,我的 gcc (GCC) 10.2.0
  1. $ PS1='$ '
  2. $ gcc --version
  3. gcc (GCC) 10.2.0
  4. Copyright (C) 2020 Free Software Foundation, Inc.
  5. This is free software; see the source for copying conditions.  There is NO
  6. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  7. $
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 20:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表