[英]C type cast for typedef defined in preprocessor block
I am trying to fix this compiler warning: 我正在尝试修复此编译器警告:
warning C4244: '=' : conversion from 'double' to 'myRealVar', possible loss of data
myRealVar is defined in a preprocessor block: myRealVar在预处理器块中定义:
#ifdef SINGLE_PRECISION
typedef float myRealVar;
#else
typedef double myRealVar;
#endif
The warning occurs on the line that basically looks like this: 警告发生在基本上看起来像这样的行上:
someVar[a][b] = 1.0/sqrt(someVar[a][b]);
I have tried C-style type casting: (myRealVar) but this doesn't seem to resolve the warning. 我尝试了C样式类型转换:(myRealVar),但这似乎无法解决警告。 How should I properly resolve this issue?
我应该如何正确解决此问题?
Edit: This did the trick. 编辑:这是把戏。 Thanks Weather Vane and Olaf.
感谢天气叶片和奥拉夫。 Not sure why my previous attempts at C-casting didn't working.
不知道为什么我以前的C广播尝试不起作用。
someVar[a][b] = (myRealVar)(1.0/sqrt(someVar[a][b]));
You need to cast the 1.0
as well as the return value from sqrt
, to remove the warning. 您需要转换
1.0
以及sqrt
的返回值,以删除警告。 Both have the type double
. 两者都具有
double
类型。
someVar[a][b] = (myRealVar)1.0 / (myRealVar)sqrt(someVar[a][b]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.