is char signed or unsigned by default on iOS?

末鹿安然 提交于 2019-11-27 06:56:22

问题


Is char signed or unsigned by default on iOS?

(I thought this would've been a well answered question, but oddly google turned up nothing at all useful!)


回答1:


In most cases, char is unsigned on ARM (for performance reasons) and signed on other platforms.

iOS differs from the normal convention for ARM, and char is signed by default. (In particular this differs from Android, where code compiled in the ndk defaults to unsigned char.)

This can be changed in xcode, there is a 'char' Type is unsigned option (which defaults to off). If this is changed to "yes", xcode will pass -funsigned-char to llvm. (Checked on xcode 5.0.2)

The reason why iOS differs is mentioned in iOS ABI Function Call Guide: ARM64 Function Calling Conventions, which says simply:

In iOS, as with other Darwin platforms, both char and wchar_t are signed types.




回答2:


why didnt you just try it?

char x,y;

x=y=0x7F;
x++;
if(x>y) unsigned else signed...


来源:https://stackoverflow.com/questions/20576300/is-char-signed-or-unsigned-by-default-on-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!