Re: void * pointer convert problem.



Christopher,

Thansk for your quick answer.
If need do casting back, that's not what I want. Following is my program. I
just want to ignore which structure it refer to. Please see line 342.

314 u_long hbHash( upm_histogram_bin_p hPtr, u_long key,
histogram_bin_type_tag hbt)
315 {
316 u_long i;
317 void* bPtr;
323 if( hbt == PROC_TIMING_BIN)
324 {
325 bPtr = (proc_timing_bin_p)(&hPtr->ptBin[0]);
326 }
327 else if(hbt == EXEC_TIMING_BIN)
328 {
329 bPtr = (exec_timing_bin_p)(&hPtr->etBin[0]);
330 }
340 for (i =0 ; i< MAX_HIST_BIN_SIZE; i++)
341 {
342 if(key < bPtr->key)
343 return i;
344 else
345 continue;
346 bPtr ++;
347 }
351 return INVALID;
352 }

Thanks,
Eric
------------------------------------------
"Christopher Benson-Manica" <ataru@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:dp3tai$3fu$1@xxxxxxxxxxxxxxxxxxx
> 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.


.