C Primer Plus 第三章打印浮点数(printf long double)

xxx123123sadf
  • 82

code showf_pt.c:

#include <stdio.h>

int main(void)
{
    float aboat = 32000.0;
    double abet = 2.14e9;
    long double dip = 5.32e5;
    printf("%f can be written %e\n", aboat, aboat);
    printf("%f can be written %e\n", abet, abet);
    printf("%f can be written %e\n", dip, dip);
    return 0;
}

output:

32000.000000 can be written 3.200000e+04
2140000000.000000 can be written 2.140000e+09
2140000000.000000 can be written 2.140000e+09

采用: /usr/loca/bin/gcc showf_pt.c -o /tmp/showf_pt 编译,
/usr/loca/bin/gcc --version:

gcc (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR     PURPOSE.

操作系统为Mac OSX。

后来改为: printf("%Lf can be written %Le\n", dip, dip);后编译正常,
同时请问如何打开编译警告?

回复
阅读 3k
1 个回答

double前加llong double前面加L-Wall打开警告。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏