Codeblocks的gcc编译器出错,double型数据输出出错。

qq_29918899 2016-04-21 12:09:38
前几天让我的CB支持C11的时候,不知道编译器设置那里手贱删了什么东西或者是设置了哪里。

后面使用的时候,遇到double型数据经常会出错,而同样的代码在DEV C就没错,哪位大神帮我看看怎么修好。

...全文
370 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiankong_bear 2016-04-21
  • 打赏
  • 举报
回复
2楼正解!!
小灸舞 2016-04-21
  • 打赏
  • 举报
回复
用%f输出double就行了 在C89中明确说明 printf("%lf", (doube)d); 的结果是未定义的。 An optional h specifying that a following d, i, o, u, x, or X conversion specifier applies to a short int or unsigned short int argument (the argument will have been promoted according to the integral promotions, and its value shall be converted to short int or unsigned short int before printing); an optional h specifying that a following n conversion specifier applies to a pointer to a short int argument; 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. C99中则说 printf("%lf", (doube)d); 相当于 printf("%f", (doube)d); l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.
羽飞 2016-04-21
  • 打赏
  • 举报
回复
这么奇葩的问题,还原一下默认配置重来一遍
ynsenyu 2016-04-21
  • 打赏
  • 举报
回复
当初满世界搜索%zu
羽飞 2016-04-21
  • 打赏
  • 举报
回复
手动执行GCC命令编译看结果试试
赵4老师 2016-04-21
  • 打赏
  • 举报
回复
%lg 笑而不语
小灸舞 2016-04-21
  • 打赏
  • 举报
回复
试验证明:无论是double %lf 还是 float %f, 无论是否设置-std=c99, 结果都没有什么不同!
qq_29918899 2016-04-21
  • 打赏
  • 举报
回复

会出现这样的提示。
qq_29918899 2016-04-21
  • 打赏
  • 举报
回复
引用 6 楼 qq423399099 的回复:
[quote=引用 5 楼 qq_29918899 的回复:] [quote=引用 2 楼 qq423399099 的回复:] 用%f输出double就行了 在C89中明确说明 printf("%lf", (doube)d); 的结果是未定义的。 An optional h specifying that a following d, i, o, u, x, or X conversion specifier applies to a short int or unsigned short int argument (the argument will have been promoted according to the integral promotions, and its value shall be converted to short int or unsigned short int before printing); an optional h specifying that a following n conversion specifier applies to a pointer to a short int argument; 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. C99中则说 printf("%lf", (doube)d); 相当于 printf("%f", (doube)d); l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.
谢谢!我改成%f就能正确输出了,所以应该是我把C99的选项给删了?在用C89?所以只用把C99或者C11调回来就行了?[/quote] 一试便知[/quote] 现在的问题是,我好像调不回C99模式了,我添加-std=c99,一点反应都没有,还是一样的错误啊。
小灸舞 2016-04-21
  • 打赏
  • 举报
回复
引用 5 楼 qq_29918899 的回复:
[quote=引用 2 楼 qq423399099 的回复:] 用%f输出double就行了 在C89中明确说明 printf("%lf", (doube)d); 的结果是未定义的。 An optional h specifying that a following d, i, o, u, x, or X conversion specifier applies to a short int or unsigned short int argument (the argument will have been promoted according to the integral promotions, and its value shall be converted to short int or unsigned short int before printing); an optional h specifying that a following n conversion specifier applies to a pointer to a short int argument; 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. C99中则说 printf("%lf", (doube)d); 相当于 printf("%f", (doube)d); l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.
谢谢!我改成%f就能正确输出了,所以应该是我把C99的选项给删了?在用C89?所以只用把C99或者C11调回来就行了?[/quote] 一试便知
qq_29918899 2016-04-21
  • 打赏
  • 举报
回复
引用 2 楼 qq423399099 的回复:
用%f输出double就行了 在C89中明确说明 printf("%lf", (doube)d); 的结果是未定义的。 An optional h specifying that a following d, i, o, u, x, or X conversion specifier applies to a short int or unsigned short int argument (the argument will have been promoted according to the integral promotions, and its value shall be converted to short int or unsigned short int before printing); an optional h specifying that a following n conversion specifier applies to a pointer to a short int argument; 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. C99中则说 printf("%lf", (doube)d); 相当于 printf("%f", (doube)d); l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.
谢谢!我改成%f就能正确输出了,所以应该是我把C99的选项给删了?在用C89?所以只用把C99或者C11调回来就行了?
qq_29918899 2016-04-21
  • 打赏
  • 举报
回复
引用 1 楼 hnwyllmm 的回复:
这么奇葩的问题,还原一下默认配置重来一遍
问题是我不知道怎么还原设置啊,我把软件卸载了,清除了注册表,删除了根目录文件,重装还是这样啊。

24,861

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧