哪些系统使用非统一指针表示?

发布于 2024-09-26 02:20:36 字数 964 浏览 3 评论 0原文

可能的重复:
是否有任何平台指向不同类型的指针有不同的大小?

我在几个地方读到,不同类型的指针在符合标准的 C 实现中可能有不同的表示形式。这是需要将指针参数强制转换为 printf 的一件事,例如,

int foo;
printf("address is %p\n", (void *) &foo);

我对此表示怀疑,并浏览了 C99 标准(文档 WG14 N1256,可在 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf)。 6.2.5.27 内容如下:

指向 void 的指针应与指向 void 的指针具有相同的表示和对齐要求。 指向字符类型的指针。类似地,指向合格或不合格版本的指针 兼容类型应具有相同的表示和对齐要求。所有指向结构类型的指针应具有相同的表示和对齐要求 彼此一样。所有指向联合类型的指针应具有相同的表示形式并且 彼此的对齐要求。 指向其他类型的指针不必具有相同的 表示或对齐要求。

因此,听起来确实符合标准的 C99 实现可以对不同类型的指针使用不同的表示。

我的问题是:存在哪些 C 实现/架构实际上对不同类型的指针使用不同的表示形式?

Possible Duplicate:
Are there are any platforms where pointers to different types have different sizes?

I have read in several places that pointers of different types may have different representations in standard-conforming C implementations. This is one thing that makes it necessary to cast pointer arguments to printf, e.g.

int foo;
printf("address is %p\n", (void *) &foo);

I was skeptical of this and poked through the C99 standard (document WG14 N1256, available at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf). At 6.2.5.27 it reads:

A pointer to void shall have the same representation and alignment requirements as a
pointer to a character type. 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.

So, it does indeed sound like a conforming C99 implementation could use different representations for pointers of different types.

My question is this: what C implementations/architectures exist that actually use different representations for pointers of different types?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞陪衬 2024-10-03 02:20:36

Classic Cray(不知道他们的新产品)无法使用常规指针寻址字符,因此 char*void* 与本机向量指针不同。

(不过,请参阅下面 Keith 的评论。可能使用了不同的 ABI,并且通过将低阶地址位旋转到高阶端,他们有时确实使“精细”和“粗略”指针与程度。)

Classic Cray (don't know about their new products) couldn't address characters with regular pointers, so char* and therefore void* were different from native vector pointers.

(See Keith's comment below, though. There may have been different ABI's in use, and by rotating the the low-order address bits to the high-order end, they did sometimes make the "fine" and "coarse" pointers compatible to a degree.)

蓝眼睛不忧郁 2024-10-03 02:20:36

最著名的可能是实模式 x86 处理器,它可以有 16 位数据指针和 32 位函数指针,具体取决于您选择的内存模型(或者您可以有 32 位数据指针和 16 位函数指针) ,或者又不同的东西......)。

Probably the most well-known is the real mode x86 processors, which could have 16-bit data pointers and 32-bit function pointers depending on the memory model you chose (or you could have 32-bit data pointers with 16-bit function pointers, or something yet again different...).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文