C++ 中存在缩小转换错误来自Android NDK的arm
我在 Android NDK 的 C++ 手臂中缩小了转换错误。
有以下代码:
int16_t ax = li.A.x, ay = li.A.y;
int16_t bx = li.B.x, by = li.B.y;
Rect16 rcA = { ax - 8, ay - 8, ax + 8, ay + 8 };
Rect16 rcB = { bx - 8, by - 8, bx + 8, by + 8 };
当尝试编译
error: narrowing conversion of '(((int)ay) + -0x00000000000000008)' from 'int' to 'int16_t' inside { }
Rect16 结构时,出现此错误:
typedef struct tagRect16 {
int16_t left, top, right, bottom;
} Rect16;
I have narrowing conversion error in C++ arm from Android NDK.
Have a following code:
int16_t ax = li.A.x, ay = li.A.y;
int16_t bx = li.B.x, by = li.B.y;
Rect16 rcA = { ax - 8, ay - 8, ax + 8, ay + 8 };
Rect16 rcB = { bx - 8, by - 8, bx + 8, by + 8 };
And get this error, when try to compile:
error: narrowing conversion of '(((int)ay) + -0x00000000000000008)' from 'int' to 'int16_t' inside { }
Rect16 struct:
typedef struct tagRect16 {
int16_t left, top, right, bottom;
} Rect16;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题源于这样一个事实:在表达式
ay - 8
中,编译器表示您正在调用int运算符-(int, int)
。您需要使用 这个问题。Your problem stems from the fact that in the expression
ay - 8
the compiler says you are callingint operator-(int, int)
. You need to tell the compiler that 8 is a short, using a method like in this question.