gpt4 book ai didi

objective-c - Objective C - 为什么 64 位意味着不同的变量类型

转载 作者:搜寻专家 更新时间:2023-10-30 19:54:59 24 4
gpt4 key购买 nike

我听说人们使用 NSInteger 或 CGFloat 等类型而不是 int 或 float 是因为与 64 位系统有关。我仍然不明白为什么这是必要的,即使我在我自己的代码中这样做。基本上,为什么 64 位系统需要更大的整数?

人们还说目前在 iOS 中没有必要,尽管将来可能需要 64 位 iPhone 等。

最佳答案

一切都在这里解释:

Introduction to 64-Bit Transition Guide

在主要 64 位更改部分:

enter image description here

Data Type Size and Alignment

OS X uses two data models: ILP32 (in which integers, long integers, and pointers are 32-bit quantities) and LP64 (in which integers are 32-bit quantities, and long integers and pointers are 64-bit quantities). Other types are equivalent to their 32-bit counterparts (except for size_t and a few others that are defined based on the size of long integers or pointers).

While almost all UNIX and Linux implementations use LP64, other operating systems use various data models. Windows, for example, uses LLP64, in which long long variables and pointers are 64-bit quantities, while long integers are 32-bit quantities. Cray, by contrast, uses ILP64, in which int variables are also 64-bit quantities.

In OS X, the default alignment used for data structure layout is natural alignment (with a few exceptions noted below). Natural alignment means that data elements within a structure are aligned at intervals corresponding to the width of the underlying data type. For example, an int variable, which is 4 bytes wide, would be aligned on a 4-byte boundary.

您可以在本文档中阅读更多内容。写得很好。我强烈推荐给你。

关于objective-c - Objective C - 为什么 64 位意味着不同的变量类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15581169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com