在 iOS 上默认是 char 签名还是 unsigned? [英] is char signed or unsigned by default on iOS?

查看:29
本文介绍了在 iOS 上默认是 char 签名还是 unsigned?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char 在 iOS 上默认是有符号还是无符号?

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!)

推荐答案

在大多数情况下,char 在 ARM 上是未签名的(对于 性能原因)并在其他平台上签名.

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

iOS 与 ARM 的常规约定不同,默认情况下为 char 签名.(特别是这与 Android 不同,where 代码在ndk中编译默认为无符号字符.)

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.)

这可以在 xcode 中更改,有一个 'char' Type is unsigned 选项(默认为关闭).如果将其更改为yes",xcode 会将 -funsigned-char 传递给 llvm.(在 xcode 5.0.2 上检查)

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)

iOS 不同的原因在 iOS ABI 函数调用指南:ARM64 函数调用约定,简单来说就是:

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

在 iOS 中,与其他 Darwin 平台一样,char 和 wchar_t 都是签名类型.

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

这篇关于在 iOS 上默认是 char 签名还是 unsigned?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆