void * vs char * [英] void * vs char *

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

问题描述

我一直在反思这两种类型的指针。至于我可以从书中获取
glean,void *和char *在功能上是等价的:

两者的关键属性是它们是可以忠实地指示的指针/>
转换为任何其他指针类型。


唯一的区别似乎是对char执行算术

是合法的但是没有空洞*。


因此,如果一个字母*真的只是一个更具功能性的空白*,那么为什么会有任何人使用空格*

在他们的代码中,而不是char *?

I''ve been reflecting on these two types of pointer. As far as I can
glean from books, void * and char * are functionally equivalent: the
key property of both is that they are pointers that can be faithfully
cast to any other pointer type.

The only difference seems to be that it is legal to perform arithmetic
on a char *, but not on a void *.

So if a char * really is just a more functional void *, why would
anyone ever use a void * in their code, instead of a char *?

推荐答案

Fr ************ @ googlemail.com 写道:

>

我一直在思考这两种类型的指针。至于我可以从书中获取
glean,void *和char *在功能上是等价的:

两者的关键属性是它们是可以忠实地指示的指针/>
转换为任何其他指针类型。


唯一的区别似乎是对char执行算术

是合法的但是没有空洞*。


因此,如果一个字母*真的只是一个更具功能性的空白*,那么为什么会有任何人使用空格*

在他们的代码中,而不是char *?
>
I''ve been reflecting on these two types of pointer. As far as I can
glean from books, void * and char * are functionally equivalent: the
key property of both is that they are pointers that can be faithfully
cast to any other pointer type.

The only difference seems to be that it is legal to perform arithmetic
on a char *, but not on a void *.

So if a char * really is just a more functional void *, why would
anyone ever use a void * in their code, instead of a char *?



void *

的唯一目的是减少程序中的演员数量。

Most可以在没有强制转换的情况下完成与void *之间的指针转换。

大多数其他指针转换需要强制转换。


在类型void,char之前发明*改为使用。


-

pete

The sole purpose of void*
is to reduce the amount of casts in a program.
Most pointer conversions to and from void* can be done without a cast.
Most other pointer conversions require a cast.

Before the invention of type void, char* was used instead.

--
pete


Fr ************ @ googlemail.com 写道:

我一直在反思这两种类型的指针。至于我可以从书中获取
glean,void *和char *在功能上是等价的:

两者的关键属性是它们是可以忠实地指示的指针/>
转换为任何其他指针类型。


唯一的区别似乎是对char执行算术

是合法的但是没有空洞*。


因此,如果一个字母*真的只是一个更具功能性的空白*,那么为什么会有任何人使用空格*

在他们的代码中,而不是一个字符*?
I''ve been reflecting on these two types of pointer. As far as I can
glean from books, void * and char * are functionally equivalent: the
key property of both is that they are pointers that can be faithfully
cast to any other pointer type.

The only difference seems to be that it is legal to perform arithmetic
on a char *, but not on a void *.

So if a char * really is just a more functional void *, why would
anyone ever use a void * in their code, instead of a char *?



为了避免从一个char *以及

之外的所有内容的转换char *。


-

Ian Collins。

To avoid casting every assignment of something other than a char* to and
from a char*.

--
Ian Collins.


文章< 11 ** ********************@n59g2000hsh.googlegroups .com> ;,

< Fr *********** *@googlemail.comwrote:
In article <11**********************@n59g2000hsh.googlegroups .com>,
<Fr************@googlemail.comwrote:

>所以如果一个char *真的只是一个更具功能性的空*,那么为什么会有人使用空格*在thei r代码,而不是char *?
>So if a char * really is just a more functional void *, why would
anyone ever use a void * in their code, instead of a char *?



char *表示它指向字符或字节。 void *不;

这意味着它指向某种未指定的类型。即使

它们之间没有功能差异,但是能够表达你的意图也是值得的。


- 理查德


-

考虑到需要多达32个字符

字母" - 1963年的X3.4。

char * means that it points to characters or bytes. void * doesn''t;
it means that it points to something of unspecified type. Even if
there was no functional difference between them, it would be
worthwhile to be able to express your intent.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


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

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