Re: A question about void pointers



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 is
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 *);
Okay. Just keep in mind that the two parameters point at the
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
.



Relevant Pages

  • Re: A question about void pointers
    ... We have a function that will alter the data and change the pointers. ... pointer variables `peter' and `molly', and not to `struct rabbit' ... I.e, rework_data a pointer to some data, massages it, and ...
    (comp.lang.c)
  • Re: A question about void pointers
    ... the prototype had generic pointers, e.g., ... and not to `struct rabbit' ... Much depends on the nature of the massaging. ...
    (comp.lang.c)
  • Re: A question about void pointers
    ... "Richard Harter" wrote in message ... struct rabbit *peter, *molly; ... the prototype had generic pointers, e.g., ... void carrot_patch ...
    (comp.lang.c)
  • Re: [SLE] Booting from USB Flash drive?
    ... Peter B Van Campen wrote: ... > Does any one have experience booting linux from a USB Thumb drive? ... > Pointers or how-to's? ... Check the headers for your unsubscription address ...
    (SuSE)
  • Re: A question about void pointers
    ... We have a function that will alter the data and change the pointers. ... pointer variables `peter' and `molly', and not to `struct rabbit' ... `char*' and `void*' have the same size and representation ...
    (comp.lang.c)