Re: A question about void pointers
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Mon, 08 Dec 2008 10:34:56 -0500
Chad wrote:
On Dec 1, 10:02 am, Eric Sosman <Eric.Sos...@xxxxxxx> wrote:Richard Harter wrote:Here is a simple problem. In the calling environment there isOkay. Just keep in mind that the two parameters point at the
a pointer to some data, e.g., an arrays of structs with a
declaration that looks something like this:
struct rabbit *peter, *molly;
We have a function that will alter the data and change the
pointers. We might call it like this:
carrot_patch(&peter,&molly);
Suppose carrot_patch is some kind of generic function that can
operate on data of many different types? It would be nice if
the prototype had generic pointers, e.g.,
void carrot_patch(void *, void *);
pointer variables `peter' and `molly', and not to `struct rabbit'
instances.
Maybe I need to think about it some more. Say
void carrot_patch(void *, void *);
is called like the following.......
carrot_patch(peter,molly);
Then would the pointer variables be 'struct rabbit' instances?
The variables `peter' and `molly' are not `struct rabbit'
instances, but pointers to `struct rabbit' instances. The two
parameters of carrot_patch() are "pointers to anything" that
are initialized by taking the values stored in `peter' and `molly'
and converting them to `void*'; they are also not `struct rabbit'
instances.
Note that the carrot_patch() call in your example is not
the same as the O.P.'s version.
--
Eric.Sosman@xxxxxxx
.
- References:
- A question about void pointers
- From: Richard Harter
- Re: A question about void pointers
- From: Eric Sosman
- Re: A question about void pointers
- From: Chad
- A question about void pointers
- Prev by Date: Re: Duplicate code
- Next by Date: Re: Duplicate code
- Previous by thread: Re: A question about void pointers
- Next by thread: Re: A question about void pointers
- Index(es):
Relevant Pages
|