Re: void * pointer convert problem.



Eric J.Hu <ehu@xxxxxxxxxx> wrote:

> vcnvt.c: In function `main':
> vcnvt.c:20: warning: dereferencing `void *' pointer

Pretty self-explanatory. You can't derefence void pointers. You can,
however, cast them back to their real type and then dereference them.

> int main()
> {
> void * vbPtr;
> counting_bin_t cBin[9];
> cBin[0].key = 9;

> vbPtr = cBin;
> printf("key is %d\n", vbPtr->key);

/* Like so */

printf( "key is %d\n", ((counting_bin_t*)vbPtr)->key );

> }

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
.