问题描述
C标准允许指针的不同类型,以具有不同的尺寸,例如的sizeof(字符*)!= sizeof的为(int *)
是允许的。它,然而,要求,如果一个指针被转换为无效*
,然后回原来的类型,则必须相等其原始值。因此,它遵循逻辑上的的sizeof(无效*)> = sizeof的(T *)
所有类型 T
,是否正确?
The C standard allows pointers to different types to have different sizes, e.g. sizeof(char*) != sizeof(int*)
is permitted. It does, however, require that if a pointer is converted to a void*
and then back to its original type, it must compare as equal to its original value. Therefore, it follows logically that sizeof(void*) >= sizeof(T*)
for all types T
, correct?
在目前使用的(X86,PPC,ARM和64位变种等),所有指针的大小等于不管所指向的本地寄存器大小(4或8个字节),最常见的平台类型。是否有任何深奥或嵌入式平台,其中三分球不同类型可能有不同的大小?我专门问的数据的三分球,虽然我也很想知道,如果有平台,其中的功能的指针都具有非同寻常的大小。
On most common platforms in use today (x86, PPC, ARM, and 64-bit variants, etc.), the size of all pointers equals the native register size (4 or 8 bytes), regardless of the pointed-to type. Are there any esoteric or embedded platforms where pointers to different types might have different sizes? I'm specifically asking about data pointers, although I'd also be interested to know if there are platforms where function pointers have unusual sizes.
我肯定的不的询问C ++的指针到成员以及指针到成员函数。那些采取共同的平台上不寻常的大小,甚至可以在一个平台内变化,这取决于指针类(非多态,单继承,多重继承,虚继承,或不完全型)的属性。
I'm definitely not asking about C++'s pointer-to-members and pointer-to-member-functions. Those take on unusual sizes on common platforms, and can even vary within one platform, depending on the properties of the pointer-to class (non-polymorphic, single inheritance, multiple inheritance, virtual inheritance, or incomplete type).
推荐答案
总理50系列用段07777,偏移0作为空指针,为PL / I最少。使用段0之后的机型,在C空指针偏移量为0,因此需要新的指令,例如TCNP(试验C空指针),显然是为了安慰所有现存的不良-编写的C code这让不正确的假设。年纪大了,字寻址总理机器也是臭名昭著的需要更大的字节指针(字符*的)余万字的指针(INT *的)。
从数据一般Eclipse的MV系列有三个其中两个是由C编译器使用的架构支持的指针格式(字,字节和比特指针),:字节指针的char *和void *的,和一切字指针。用于从16位诺瓦线的32位中压线的进化过程中的历史原因,字指针和字节指针已偏移在字不同的地方,间接和环保护比特。传递不匹配的指针格式功能导致保护错误。最终,MV C编译器添加了许多兼容性选项,以试图解决code,它有指针类型不匹配错误。
The Eclipse MV series from Data General has three architecturally supported pointer formats (word, byte, and bit pointers), two of which are used by C compilers: byte pointers for char * and void *, and word pointers for everything else. For historical reasons during the evolution of the 32-bit MV line from the 16-bit Nova line, word pointers and byte pointers had the offset, indirection, and ring protection bits in different places in the word. Passing a mismatched pointer format to a function resulted in protection faults. Eventually, the MV C compiler added many compatibility options to try to deal with code that had pointer type mismatch errors.
有些霍尼韦尔牛市大型机使用的位模式为06000(内部)空指针。
Some Honeywell-Bull mainframes use the bit pattern 06000 for (internal) null pointers.
疾病预防控制中心网络180系列拥有包括戒指,段和偏移的48位指针。多数用户(在环11)有0xB00000000000的空指针。这是常见的旧CDC那些补机器使用一个全1位字为各种数据,包括无效地址的特殊标志。
The CDC Cyber 180 Series has 48-bit pointers consisting of a ring, segment, and offset. Most users (in ring 11) have null pointers of 0xB00000000000. It was common on old CDC ones-complement machines to use an all-one-bits word as a special flag for all kinds of data, including invalid addresses.
旧的HP 3000系列采用了比字地址字节地址不同的寻址方案;像一些它上面的机器,因此对使用的char *和void *指针比其他不同的指针再presentations。
The old HP 3000 series uses a different addressing scheme for byte addresses than for word addresses; like several of the machines above it therefore uses different representations for char * and void * pointers than for other pointers.
在对符号Lisp机器,带标签的架构,甚至没有传统的数字指针;它使用对(基本上是不存在的句柄)为C空指针。
The Symbolics Lisp Machine, a tagged architecture, does not even have conventional numeric pointers; it uses the pair (basically a nonexistent handle) as a C null pointer.
根据所使用的``内存模型',8086系列处理器(PC
兼容机)可以使用16位的数据指针和32位功能
指针,反之亦然。
Depending on the ``memory model'' in use, 8086-family processors (PC compatibles) may use 16-bit data pointers and 32-bit function pointers, or vice versa.
一些64位的Cray机器重新present为int *中的低48位
字;字符*另外使用了一些的高16位的指示
一个字内的字节地址。
Some 64-bit Cray machines represent int * in the lower 48 bits of a word; char * additionally uses some of the upper 16 bits to indicate a byte address within a word.
附加链接:克里斯托雷克一个
一些这些机器。
Additional links: A message from Chris Torek with more details about some of these machines.
这篇关于是否有任何的平台,其中三分球不同类型有不同的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!