Re: typedef function with void parameters
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Thu, 13 Dec 2007 15:24:38 +0000
William Xu <william.xwl@xxxxxxxxx> writes:
Chris Dollin <chris.dollin@xxxxxx> writes:
So, which do you want -- a function taking a `void*` or a function taking
a `char*`? They're not compatible types. Pick one.
Oh, i thought that most pointer types could be converted/stored into
void pointer.
This is true of object pointers but not function pointers.
I'm trying to wrap different function pointers into FUNC,
like,
,----
| int foo(char *p){}
| int bar(int *p){}
|
| typedef int (*FUNC)(void *);
|
| FUNC f1 = foo, f2 = bar;
`----
So, this is not allowed?
Allowed is vague. It is a constraint violation and thus requires a
diagnostic (but that could be "I will convert these function pointers
for you" or it might be "Yuck! -- compilation halted").
If you convert (with a cast) it will work on some systems but it is
not guaranteed -- your code could break with a compiler update or even
a change in optimisation level. If you are prepared to take a chance,
always make sure that the call is though a pointer whose type matches
the type of function being called.
--
Ben.
.
- Follow-Ups:
- Re: typedef function with void parameters
- From: David Thompson
- Re: typedef function with void parameters
- References:
- typedef function with void parameters
- From: William Xu
- Re: typedef function with void parameters
- From: Chris Dollin
- Re: typedef function with void parameters
- From: William Xu
- typedef function with void parameters
- Prev by Date: Re: Trouble with integer floating point conversion
- Next by Date: Re: typedef function with void parameters
- Previous by thread: Re: typedef function with void parameters
- Next by thread: Re: typedef function with void parameters
- Index(es):
Relevant Pages
|