該API提供了一個函數signed char getDirection();
,返回1表示「forward」,0表示「不動」,-1表示「後退」。如何將Signed Char與文字常量進行比較?
,當然還有,在thesequestions解釋,一個簡單的比較:
if(getDirection() == -1) { ... }
失敗。好吧,我明白爲什麼它會失敗。但我無法找到如何使其工作!我嘗試了左側鑄造(int)
,右側(signed char)
,還是虛無縹緲......
編輯:
signed char a = getDirection();
printf("%d\n",(int) a);
printf("%d\n",(int) getDirection());
結果:
-1
255
EDIT2:每個請求:
const signed char getDirection(uchar d)
{
if(d >= config.directional_inputs.channelCount) return -2;
return shm->input_state.directional_inputs[d].direction;
}
@AlexD:我希望。那麼,實際上測試語句的格式爲'printf(「val:%d,compare:%d」,getDirection(),(getDirection()== DIRECTION_BACK));'常量是'#define DIRECTION_BACK -1' –
你的代碼是正確的。檢查getDirection()是否實際返回-1。顯示你的'printf'的輸出。同時顯示你的實際代碼,也許只是一個流浪';'某處。 –
@MichaelWalz:輸出:「val:-1,比較:0」。一位同事懷疑編譯器錯誤。 –