D
der
Hello all,
I've a question about functions that takes as an argument a void *, and
change its content. e.g, meset(void *s, int c, size_t n);
Why does it work? The only solution I can think of is that these functions
will define a local pointer-to-pointer of a specific type(int in memset()
?), and manipulate the content of the void * with the pointer-to-pointer.
If so, how would they know the type of the pointer-to-pointer?
here is a code that explains my thought:
int
main(void)
{
char *c = malloc(1); /* just one byte */
void func(void *);
func(c);
printf("%c\n", *c);
return 0;
}
void
func(void *c)
{
char **p;
p = (char **) &c;
**p='v';
}
Thanks a whole lot for you great help.
I've a question about functions that takes as an argument a void *, and
change its content. e.g, meset(void *s, int c, size_t n);
Why does it work? The only solution I can think of is that these functions
will define a local pointer-to-pointer of a specific type(int in memset()
?), and manipulate the content of the void * with the pointer-to-pointer.
If so, how would they know the type of the pointer-to-pointer?
here is a code that explains my thought:
int
main(void)
{
char *c = malloc(1); /* just one byte */
void func(void *);
func(c);
printf("%c\n", *c);
return 0;
}
void
func(void *c)
{
char **p;
p = (char **) &c;
**p='v';
}
Thanks a whole lot for you great help.