android ndk開發中char和unsigned char問題

官方說明

看看cflags中 fsigned-char的說明:

-fsigned-char — Allows the type char in the native libraries to be signed, like signed char. Each kind of machine has a default for what char should be. It is either like unsigned charby default or like signed char by default. By default on Android NDK char type is unsigned, but char is treated as signed on x86. This is an option imposed by Superpowered SDK authors, so we’ll include this as well.

默認android ndk中char類型是unsigned,在x86上是signed類型。。

ndk中,對於負數來說,char val = -3,printf出的值是253,而不是-3。。差距這麼大的值,在項目中會有意外的表現。。

 

不想該代碼的話,可以使用下面的設置,進行修改:

LOCAL_CFLAGS := -fsigned-char

出自網站:https://expertise.jetruby.com/android-ndk-using-c-c-native-libraries-to-write-android-apps-21550cdd86a

 

申明

 

 

發佈了218 篇原創文章 · 獲贊 94 · 訪問量 95萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章