简体   繁体   English

在使用分段寻址模式的 16 位系统上,`size_t`、`uintptr_t`、`intptr_t` 和 `ptrdiff_t` 类型的实际大小是多少?

[英]What's the real size of `size_t`, `uintptr_t`, `intptr_t` and `ptrdiff_t` type on 16-bit systems using segmented addressing mode?

Well, size_t , uintptr_t , intptr_t and ptrdiff_t type defined in C programming language really puzzles me.好吧,C 编程语言中定义的size_tuintptr_tintptr_tptrdiff_t类型真的让我感到困惑。

I noticed that on 32-bit systems using flat memory mode , the real size of above four types is:我注意到在使用flat memory mode 的32 位系统上,上述四种类型的实际大小是:

sizeof(size_t) = sizeof(uintptr_t) = sizeof(intptr_t) = sizeof(ptrdiff_t) = 4

And on 64-bit systems using flat memory mode , the real size of above four types is:而在使用flat memory 模式的64 位系统上,上述四种类型的实际大小为:

sizeof(size_t) = sizeof(uintptr_t) = sizeof(intptr_t) = sizeof(ptrdiff_t) = 8

But, I'm still curious about the real size of these four types on 16-bit systems using segmented addressing mode .但是,我仍然对使用分段寻址模式的16 位系统上这四种类型的实际大小感到好奇。

According to Windows 3.1x , Windows 3.1x is a series of 16-bit operating systems.根据Windows 3.1x ,Windows 3.1x 是一系列 16 位操作系统。 But I can't find a suitable C language compiler to test and validate the real answer.但是我找不到合适的 C 语言编译器来测试和验证真正的答案。

In real mode , size_t and ptrdiff_t are 16 bit types.实模式下size_tptrdiff_t是 16 位类型。 The size of a pointer depends on whether it's a near, far, or huge pointer.指针的大小取决于它是 指针 、远指针 还是大指针。 Near pointers have 16 bits, the other 32 bits.近指针有 16 位,其他 32 位。 intptr_t and uintptr_t were only defined much later in C99. intptr_tuintptr_t只是在 C99 中定义的很晚。

That, at least potentially, depends on which compiler you are using.这至少可能取决于您使用的编译器。

As a data point from the 16-bit era, the Borland Turbo C++ 3.0 manual has this to say:作为16位时代的一个数据点,Borland Turbo C++ 3.0手册是这样说的:

The integer type of the result of sizeof is size_t , defined as unsigned int in stddef.h. sizeof结果的整数类型是size_t ,在 stddef.h 中定义为unsigned int

(emphasis in original.) (强调原文。)

The size of unsigned int was 16 bits, independent of the memory model. unsigned int的大小为 16 位,与内存模型无关。

(None of the other types you asked about existed yet, or, if they did, were not supported by this particular compiler.) (您询问的其他类型都不存在,或者,如果存在,则此特定编译器不支持。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM