Re: void * pointer convert problem.
- From: "David Resnick" <lndresnick@xxxxxxxxx>
- Date: 30 Dec 2005 11:23:08 -0800
Eric J.Hu wrote:
> 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
Hi Eric,
Conversations make more sense that way.
Folks here don't like top posting, please post after the thing being
replied to.
(above two lines flipped on purpose)
Anyway, I think you aren't clear on the issue with the way
you are trying to use void *.
You (or at least the compiler) can't know without casting
or assigning to something with a non-void type what object type a
pointer to void actually refers to. You are saying on line 342 that
bPtr, a pointer to void, is actually a pointer to some struct that has
a
key field. But the compiler has no way to know what type of structure
that may be (or in particular, what the offset of the key field is
within that
structure).
-David
.
- References:
- void * pointer convert problem.
- From: Eric J.Hu
- Re: void * pointer convert problem.
- From: Christopher Benson-Manica
- Re: void * pointer convert problem.
- From: Eric J.Hu
- void * pointer convert problem.
- Prev by Date: Printf question.
- Next by Date: Re: void * pointer convert problem.
- Previous by thread: Re: void * pointer convert problem.
- Next by thread: Re: void * pointer convert problem.
- Index(es):
Relevant Pages
|