Re: typedef function with void parameters
- From: David Thompson <dave.thompson2@xxxxxxxxxxx>
- Date: Mon, 24 Dec 2007 00:57:13 GMT
On Thu, 13 Dec 2007 15:24:38 +0000, Ben Bacarisse
<ben.usenet@xxxxxxxxx> wrote:
William Xu <william.xwl@xxxxxxxxx> writes:
| int foo(char *p){}
| int bar(int *p){}
|
| typedef int (*FUNC)(void *);
|
| FUNC f1 = foo, f2 = bar;
Right. Although I am a bit surprised that the OP's version of gccSo, 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").
defaults the diagnostic to an error; mine make it a warning.
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.
_If_ you convert back to the correct (func pointer) type before
calling, it IS guaranteed to work. (Converting to and) calling through
the wrong pointer pointer is not guaranteed, and indeed could break,
although I'd be surprised if optimization does so -- C is usually and
traditionally implemented with separate compilation and linking, for
which optimization that doesn't eliminate a call entirely (inlining)
can usually change calling conventions only in very limited ways.
- formerly david.thompson1 || achar(64) || worldnet.att.net
.
- 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
- Re: typedef function with void parameters
- From: Ben Bacarisse
- typedef function with void parameters
- Prev by Date: Re: Determine the maximum of two integers.
- Next by Date: Re: Macro substitution conundrum
- Previous by thread: Re: typedef function with void parameters
- Next by thread: Re: typedef function with void parameters
- Index(es):
Relevant Pages
|