从void **转换为char **有多危险 [英] How dangerous is conversion from void ** to char **

查看:167
本文介绍了从void **转换为char **有多危险的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们知道标准不会强制指针大小相等. (此处此处)(而非谈论函数指针)

So we know that the standard doesn't force pointer sizes to be equal. (here and here) (and not talking about function pointers)

我想知道实际上这可能是个问题.我们知道void *可以容纳任何内容,因此如果指针大小不同,那将是最大大小.鉴于此,将void **分配给char **意味着麻烦.

I was wondering how in reality that can be an issue. We know that void * can hold anything, so if the pointer sizes are different, that would be the biggest size. Given that, assigning a void ** to a char ** means trouble.

我的问题是,假设void *char *具有相同的大小将有多危险?真的有一个不正确的架构吗?

My question is how dangerous would it be to assume void * and char * have the same size? Is there actually an architecture where this is not true?

此外,我不希望听到16位dos信息! ;)

Also, 16-bit dos is not what I want to hear! ;)

推荐答案

void *char *保证具有相同的大小.

void * and char * are guaranteed to have the same size.

void **不能保证具有与char **相同的大小(但是在实现上非常有可能).

void ** is not guaranteed to have the same size as char ** (but very likey on your implementation they will).

(C99,6.2.5p27)指向void的指针应与指向字符类型的指针具有相同的表示和对齐要求.指向其他类型的指针不必具有相同的表示或对齐要求.

(C99, 6.2.5p27) "A pointer to void shall have the same representation and alignment requirements as a pointer to a character type [...] Pointers to other types need not have the same representation or alignment requirements."

这篇关于从void **转换为char **有多危险的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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