Eric Sosman <Er*********@su n.comwrites:
Oliver Block wrote On 09/04/07 11:01,:
>Hello,
sometimes you can read that a function requiring an argument of tpye
void ** is submitted something like the following:
mystruct **ppval;
myfunc((void **)&ppval, ...);
I would expect that one would instead use
myfunc((void **)ppval, ...);
Why would one use the first and what is the difference to using the
second call?
Both are probably wrong.
One possibility is that the author of myfunc() assumed
that all data pointers have the same representation. He's
trying to use the void** argument to find his way to some
other pointer in memory, and then trying to manipulate that
other pointer as if it were a void*, regardless of what it
actually is. If this is the case, myfunc() is a bug looking
for a place to sting. It will find one as soon as it's run
on a machine where different "flavors" of pointers exist.
[...]
Right. 'void*' can be used as a generic pointer type. Any pointer
value (well, any pointer-to-object value, not a function pointer) can
be converted to void* and back again with no loss of information,
and the conversion can be done implicitly.
It's tempting to use 'void**' as a generic pointer-to-pointer type,
but there is no generic pointer-to-pointer type.
--
Keith Thompson (The_Other_Keit h)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"