对于所有数据类型,在一个平台中所有数据指针的大小是否相同? [英] Are all data pointers the same size in one platform for all data types?

查看:28
本文介绍了对于所有数据类型,在一个平台中所有数据指针的大小是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char*int*long* 甚至 long long* 是否具有相同的大小(在给定的平台)?

解决方案

不能保证它们的大小相同,尽管在我有经验的平台上它们通常是相同的.

C 2011 在线草案:

<块引用>6.2.5 类型
...
28    指向 void 的指针应具有与指向字符类型的指针.48) 类似地,指向字符类型的限定或非限定版本的指针兼容类型应具有相同的表示和对齐要求.全部指向结构类型的指针应具有相同的表示和对齐要求作为彼此.所有指向联合类型的指针都应具有相同的表示和对齐要求.指向其他类型的指针不需要相同表示或对齐要求.<小时>48) 相同的表示和对齐要求意味着与函数的参数、函数的返回值和联合的成员.

Are char*, int*, long* or even long long* of same size (on a given platform)?

解决方案

They're not guaranteed to be the same size, although on the platforms I have experience with they usually are.

C 2011 online draft:

6.2.5 Types
...
28     A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.48) Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements.
48) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and members of unions.

这篇关于对于所有数据类型,在一个平台中所有数据指针的大小是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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