在来自 Android NDK 的 C++ arm 中出现缩小转换错误
问题描述:
我在来自 Android NDK 的 C++ arm 中出现缩小转换错误.
I have narrowing conversion error in C++ arm from Android NDK.
有以下代码:
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 结构体:
Rect16 struct:
typedef struct tagRect16 {
int16_t left, top, right, bottom;
} Rect16;
答
你的问题源于在表达式 ay - 8
中编译器说你正在调用 int operator-(int, int)
.您需要使用 这个问题.
Your problem stems from the fact that in the expression ay - 8
the compiler says you are calling int operator-(int, int)
. You need to tell the compiler that 8 is a short, using a method like in this question.