Re: Baffled by this ... (casting of function pointers)
- From: Lawrence Kirby <lknews@xxxxxxxxxxxxxxx>
- Date: Fri, 26 Aug 2005 12:28:43 +0100
On Thu, 25 Aug 2005 20:43:33 -0700, Barry Schwarz wrote:
> On Fri, 26 Aug 2005 00:42:00 +0000 (UTC), Alfonso Morra
> <sweet-science@xxxxxxxxxxxx> wrote:
>
>>How can this work ?
>>
>>I have the following declarations in a header:
>>
>>Header
>>=========
>>typedef void (*VFPTR)(void) ;
>>void FOO_Callback(void*, char*, char*, int, unsigned long, void*,void*);
>>int bar(int *, char *, VFPTR, void *);
>>
>>Source
>>=========
>>In the C source code, I come accross this line:
>>
>>bar(&id, name, FOO_Callback, (void *)handle);
>
> The cast on handle is superfluous if it is a pointer of any type.
> Since the prototype for bar is known, any pointer type will be
> implicitly converted void* as part of evaluating the arguments.
Only pointers to unqualified object or imcomplete types can be converted
implicitly to void *. Function pointers can't nor can pointers with types
like const int * or indeed const void *. However this is a good thing and
attempts at conversions like these should be warned about so the code is
much better without the cast.
Lawrence
.
- References:
- Baffled by this ... (casting of function pointers)
- From: Alfonso Morra
- Re: Baffled by this ... (casting of function pointers)
- From: Barry Schwarz
- Baffled by this ... (casting of function pointers)
- Prev by Date: Re: access() doesn't work when a file is open
- Next by Date: Re: Baffled by this ... (casting of function pointers)
- Previous by thread: Re: Baffled by this ... (casting of function pointers)
- Next by thread: Re: Baffled by this ... (casting of function pointers)
- Index(es):
Relevant Pages
|