我以为我很了解C,但这让我很感兴趣。 我意识到这完全脱离了背景,但程序很漂亮 很复杂,我认为无论如何都不会理解这一点。 如果这里有人有洞察力,我会非常感激。 Jason Sewall Hello, I''m using the intel C++ 8.0 compiler on windows and I''m working on somesoftware that uses the following lines of code: gf->invdim = 1.0/(double)dim;printf("invdim: %f\n", (float)gf->invdim); dim is an integer, gf->invdim a double. I always get "-1.#IND00" as theoutput of this code, no matter the value of dim, but only at certainstages in the code. If I duplicate the code like so: gf->invdim = 1.0/(double)dim;printf("invdim: %f\n", (float)gf->invdim);gf->invdim = 1.0/(double)dim;printf("invdim: %f\n", (float)gf->invdim); The first output is the NAN but the second is the expected result. I thought I understood C pretty well, but this is weirding me out. I realize that this is grossly out of context but the program is prettycomplicated and I don''t think it would help understand this anyway. If anyone here has an insight, I''d be much obliged. Jason Sewall推荐答案 对不起,这里有一个快速的跟进(非常快,我发布了父母只有两个 分钟前)。 我用英特尔8.0在发布中编译了它。模式。没问题。 (问题在父级中描述的在英特尔调试模式下发生。 在MSVC 6调试中,没问题。同样适用于发布。 在我的程序中必须存在某种错误,只有英特尔调试 暴露,英特尔的一个错误或一些奇怪的调试设置,我不会 b $ b明白。 无论如何,欢迎你提出意见! 杰森 杰森Sewall写道:Sorry, here''s a quick followup (very quick, I posted the parent just twominutes ago). I compiled it with intel 8.0 in "Release" mode. No problem. (The problemdescribed in parent occured in intel "debug" mode. In MSVC 6 Debug, no problem. Ditto for Release. There must be some sort of bug in my program that only intel debugexposes, a bug in intel, or some weird debug setting that I don''tunderstand. Anyway, your comments are welcome! JasonJason Sewall wrote:你好, 我正在使用Windows上的intel C ++ 8.0编译器,我正在开发一些使用以下软件的软件代码行: gf-> invdim = 1.0 /(double)dim; printf(" invdim:%f \ n",(float)gf-> invdim ); dim是一个整数,gf-> invdim一个double。我总是得到-1。#IND00作为此代码的输出,无论值是多少昏暗,但只在代码中的某些阶段。 如果我像这样复制代码: gf-> invdim = 1.0 /(double)dim; printf(" invdim:%f \ n",(float)gf-> invdim); gf-> invdim = 1.0 /(double)dim; printf(" invdim:%f \ n",(float)gf-> invdim); 第一个输出是NAN但第二个是预期的结果。 我以为我很了解C,但是这让我很沮丧。 我意识到这完全脱离了背景但是程序非常复杂,我认为无论如何都不会理解这一点。 如果这里的任何人有洞察力,我会非常感激。 Hello, I''m using the intel C++ 8.0 compiler on windows and I''m working on some software that uses the following lines of code: gf->invdim = 1.0/(double)dim; printf("invdim: %f\n", (float)gf->invdim); dim is an integer, gf->invdim a double. I always get "-1.#IND00" as the output of this code, no matter the value of dim, but only at certain stages in the code. If I duplicate the code like so: gf->invdim = 1.0/(double)dim; printf("invdim: %f\n", (float)gf->invdim); gf->invdim = 1.0/(double)dim; printf("invdim: %f\n", (float)gf->invdim); The first output is the NAN but the second is the expected result. I thought I understood C pretty well, but this is weirding me out. I realize that this is grossly out of context but the program is pretty complicated and I don''t think it would help understand this anyway. If anyone here has an insight, I''d be much obliged. Jason Sewall Jason Sewall写道:Jason Sewall wrote:你好, 我正在使用Windows上的intel C ++ 8.0编译器,而且我正在开发一些使用以下代码行的软件: gf-> invdim = 1.0 /(双)暗淡; ^^^^^^ 无意义强制转换,转换为浮点数由1.0 printf(invdim:%f \ n,(float)gf->触发; invdim); Hello, I''m using the intel C++ 8.0 compiler on windows and I''m working on some software that uses the following lines of code: gf->invdim = 1.0/(double)dim;^^^^^^pointless cast, the conversion to floating point is triggered by the 1.0 printf("invdim: %f\n", (float)gf->invdim); ^^^^^^^ 无意义演员。 %f是双重的说明符 ^^^^^^^pointless cast. %f is the specifier for a double Jason Sewall写道:Jason Sewall wrote: 你好, 我我正在使用Windows上的intel C ++ 8.0编译器,而且我正在开发一些使用以下代码行的软件: gf-> invdim = 1.0 /(double dim; printf(" invdim:%f \ n",(float)gf-> invdim); 演员阵容毫无意义。 printf无论如何都会收到双倍的值。 dim是一个整数,gf-> invdim是double。我总是得到-1。#IND00作为此代码的输出,无论是昏暗的值,还是只在代码中的某些阶段。 我发布的代码中没有任何内容可以引发这样的输出(除非dim为0,我认为你已经考虑过了)。 如果这里有人有洞察力,我会非常感激。 Hello, I''m using the intel C++ 8.0 compiler on windows and I''m working on some software that uses the following lines of code: gf->invdim = 1.0/(double)dim; printf("invdim: %f\n", (float)gf->invdim);The cast is pointless. printf will receive the value as a double anyway. dim is an integer, gf->invdim a double. I always get "-1.#IND00" as the output of this code, no matter the value of dim, but only at certain stages in the code.I can see nothing in the code you posted that would provoke such anoutput (unless dim were 0, which I presume you already considered). If anyone here has an insight, I''d be much obliged. 这个问题几乎肯定存在于其他地方。我相信你是在看炸弹的登陆地点,而不是它的发射地点。我不会在不看代码的情况下推测可能的原因。 The problem almost certainly lies elsewhere. I believe that you arelooking at the bomb''s landing site, not its launch site. I wouldn''tlike to speculate on possible causes without seeing the code. 这篇关于疯狂(?)C问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-15 16:05