从一个函数传递到另一个函数的值发生了变化...不明白为什么?
我有一个非常奇怪的问题,我无法理解。
这是 C 代码:
//below are the values being passed
//long numTreePeriods = 80
//double length = 0.23013698630136986
TTimeLineInfo* tlInfo = GtoTimeLineInfoNew( (long)ceil(numTreePeriods/length), /*ppy*/
0L,
1,
FALSE);
现在这是上面调用的 GtoTimeLineInfoNew 函数的签名:
__declspec(dllexport) TTimeLineInfo* GtoTimeLineInfoNew
(long minPPY, /* (I) Min # ppy before switchDate */
TDate switchDate, /* (I) If 0, ignore ppy2; only use minPPY*/
long minPPY2, /* (I) Min # ppy after switchDate */
TBoolean wholeDayTPs);
当我调试代码并使用上面指定的值单步执行函数时,我得到:
minPPY = -1636178017
??????什么可能导致这种行为?
准确地说,C 代码是我用 C++/CLI 封装的 dll。尽管如此,问题似乎与此无关......
I have a very weird problem that I can't understand.
This is C code:
//below are the values being passed
//long numTreePeriods = 80
//double length = 0.23013698630136986
TTimeLineInfo* tlInfo = GtoTimeLineInfoNew( (long)ceil(numTreePeriods/length), /*ppy*/
0L,
1,
FALSE);
Now here's the signature of the GtoTimeLineInfoNew function called above:
__declspec(dllexport) TTimeLineInfo* GtoTimeLineInfoNew
(long minPPY, /* (I) Min # ppy before switchDate */
TDate switchDate, /* (I) If 0, ignore ppy2; only use minPPY*/
long minPPY2, /* (I) Min # ppy after switchDate */
TBoolean wholeDayTPs);
When I debug my code and step into the function with the values specified above I get:
minPPY = -1636178017
????? What could cause this type of behaviour?
Just to precise the C code is a dll I am wrapping up in C++/CLI. Nevertheless the problem seems independent from that....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定;但我的猜测是参数传递给 C 函数与 C++ 函数的方式之间存在差异。尝试:
I'm not certain; but my guess would be a difference between how parameters are passed to a C function vs. a C++ function. Try:
由于某种原因 ceil(numTreePeriods/length) 给出了一些非常奇怪的东西。所以我自己写了一个 ceil 函数来解决这个问题...
更新:
就像 glglgl 的注释中突出显示的那样,缺少适当的标头,因此 ceil 被解释为返回一个 int ,这导致了有趣的值...
For some reason
ceil(numTreePeriods/length)
was giving something very weird. So I wrote a ceil function myself to solve this problem...UPDATE:
Like highlighted in comment by glglgl, the appropriate header was missing, hence ceil was interpreted to return an int which led to funny values...