问题被证实无效* [英] question realted to void *

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

问题描述

伙计们,


考虑一个函数

func(void ** var)

{


/ *在函数中我需要将变量var类型化为(int **)

我的意思是说,我需要访问var as(int **)


}


我的问题是什么是更好的选择,我应该使用

func(void ** var)或者

func(void * var)。


我认为func(void *)应该没问题,因为我们可以存储任何类型的

指针变量 invoid pointer variable。

void指针变量应足够大,可以容纳任何类型的指针

变量。


这是正确的吗?或者我错过了什么?


如果这是正确的,我们应该使用void **吗?


感谢任何帮助/回应。


Guys,

Consider a function
func(void **var)
{

/* In function I need to typecast the variable var as (int **)
I mean to say, I need to access var as (int **)

}

My question is what is the better option, should I use
func(void **var) Or
func(void *var).

I think func(void *) should be fine, as we can store any type of
"pointer variable" in "void pointer variable".
void pointer variable should be big enough to hold any type of pointer
variable.

Is that correct? Or I am missing something?

And if that is correct, should we ever use void ** ?

thanks for any help/response.


推荐答案

9月16日,4:54 * pm,junky_fel ... @ yahoo.co .in"

< junky_fel ... @ yahoo.co.inwrote:
On Sep 16, 4:54*pm, "junky_fel...@yahoo.co.in"
<junky_fel...@yahoo.co.inwrote:

伙计们,


* *考虑一个函数

func(void ** var)

{


/ *在函数I中需要将变量var转换为(int **)

* *我的意思是说,*我需要访问var as(int **)


}


我的问题是什么是更好的选择,我应该使用

func(void ** var)*或

func(void * var)。


我认为func(void *)应该没问题,因为我们可以存储任何类型的

指针变量 ; invoid pointer variable。

void指针变量应足够大,可以容纳任何类型的指针

变量。


这是正确的吗?或者我错过了什么?


如果这是正确的,我们应该使用void **吗?


感谢任何帮助/回应。
Guys,

* *Consider a function
func(void **var)
{

/* In function I need to typecast the variable var as (int **)
* *I mean to say, *I need to access var as (int **)

}

My question is what is the better option, should I use
func(void **var) *Or
func(void *var).

I think func(void *) should be fine, as we can store any type of
"pointer variable" in "void pointer variable".
void pointer variable should be big enough to hold any type of pointer
variable.

Is that correct? Or I am missing something?

And if that is correct, should we ever use void ** ?

thanks for any help/response.



你可以把任何东西投射到任何你想要的东西上,但是你可以做到的东西越少,就越难以让你感到困惑。理想情况下,func()将采用int ** var。如果

就是它的真实含义。但是,有时,在这种情况下似乎是真的

,有必要使用void。如果你需要使用void,

那么我仍然会更喜欢void **如果你传递的确是一个

指针指针。


对我而言,重要的是你如何投射var在函数内部,

是函数签名告诉客户端调用者的内容。如果我要去

来调用带有签名func(void *)的函数。然后我希望

传递一个指针,而不是一个指向指针的指针。例如:


void f1(void *);

void f2(void **);


int x = 0;

int * px =& x;


f1(px); / *指针* /

f2(& px); / *指针指针* /


Adam

You can cast anything to anything you want, but the less confusing you
can make it, the better. Ideally, func() would take an "int** var" if
that is what it really is. However, sometimes, as appears to be true
in this case, it is necessary to use void. If you need to use void,
then I would still prefer "void**" if what you are passing really is a
pointer-to-pointer.

To me what matters more than how you cast "var" inside the function,
is what the function signature tells the client caller. If I''m going
to call a function with a signature "func(void*)" then I expect to
pass a pointer, not a pointer-to-pointer. For example:

void f1(void*);
void f2(void**);

int x = 0;
int* px = &x;

f1(px); /* pointer */
f2(&px); /* pointer to pointer */

Adam


ju ********** @ yahoo.co.in 写道:

伙计们,


考虑一个函数

func(void ** var)

{


/ *在函数中我需要将变量var类型化为(int **)

我的意思是说,我需要访问var as(int **)


}


我的问题是什么是更好的选择,我应该使用

func(void ** var)或

func(void * var)。


我认为func(void *)应该没问题,因为我们可以存储任何类型的

指针变量 invoid pointer variable。

void指针变量应足够大,可以容纳任何类型的指针

变量。


这是正确的吗?或者我错过了什么?
Guys,

Consider a function
func(void **var)
{

/* In function I need to typecast the variable var as (int **)
I mean to say, I need to access var as (int **)

}

My question is what is the better option, should I use
func(void **var) Or
func(void *var).

I think func(void *) should be fine, as we can store any type of
"pointer variable" in "void pointer variable".
void pointer variable should be big enough to hold any type of pointer
variable.

Is that correct? Or I am missing something?



这是不确定的,因为你已经告诉我们你打算怎么打算b $ b做什么而不是你做什么重新尝试。答案

我应该使用螺丝刀还是锤子?无论你是想开一个螺丝钉,钉一个钉子,还是申请

油漆......


也许你所缺少的是不同的b / b
类型的指针是不可互换的 - 也就是说,你还没有理解

问题4.9 in常见问题。但很难确定,基于

您对目标的粗略描述。

It''s not certain, because you''ve told us how you intend to
do something but not what you''re trying to do. The answer to
"Should I use a screwdriver or a hammer?" depends greatly on
whether you''re trying to drive a screw, hammer a nail, or apply
paint ...

Perhaps what you''re missing is that pointers of different
types aren''t interchangeable -- that is, you''ve not understood
question 4.9 in the FAQ. But it''s hard to be sure, based on
your rather sketchy description of your goals.


如果这是正确的,我们应该使用void **吗?
And if that is correct, should we ever use void ** ?



我会通过逗号忽略所有内容,因为

没有足够的信息来评估它。至于其余部分,无效**

很少出现,但有时确实有意义。


-
呃********* @ sun.com




< ju ********** @ yahoo.co.inwrote in message

<ju**********@yahoo.co.inwrote in message

>

如果这是正确的,我们应该使用void **吗?
>
And if that is correct, should we ever use void ** ?



void **用于指向任意内存缓冲区的指针列表。

void *用于指向任意内存缓冲区的指针。

由于任意内存缓冲区可以包含指针列表,因此您始终可以
使用void *,就像你可以使用任何其他类型一样。


所以问题是,所有参数都应该作为void *传递 ?"


答案是否定的。只是偶尔隐藏来自调用函数的

指针的类型才有意义。使用实际类型可以在编译器中检查

,并且更容易阅读。


-

免费游戏和编程好东西。
http://www.personal.leeds.ac .uk / ~bgy1mm

A void ** is for a list of pointers to arbitrary memory buffers.
A void * is for a pointer to an arbitary memory buffer.

Since arbitrary memory buffers can contain lists of pointers, you can always
use a void *, just as you could for any other type.

So the question is really, "should all parameters be passed as void *''s?"

The answer is no. Only occasionally does it make sense to hide the type of
pointer from the calling function. Use of actual types enables checking in
the compiler, and is easier to read.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


这篇关于问题被证实无效*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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