Re: Problem with pointer to function - what's wrong here?
- From: "David T. Ashley" <dta@xxxxxxxx>
- Date: Wed, 31 Jan 2007 16:52:21 -0500
"Charles Sullivan" <cwsulliv@xxxxxxxxxxxx> wrote in message
news:pan.2007.01.31.21.27.32.590782@xxxxxxxxxxxxxxx
I define and initialize an array of structures like the following,
(where the <verbiage within angle brackets> is just meant to be
explanatory):
int func1(<argument prototypes>);
int func2(<argument prototypes>);
struct mystruct {
<other stuff>;
int (*myfunc)();
} myrecords[] = {
{<other stuff value>, func1},
{<other stuff value>, NULL },
{<other stuff value>, func2}
};
int func1(<argument list>)
{
<blah-blah-blah1>
}
int func2(<argument list>)
{
<blah-blah-blah2>
}
I've always believed this was legal code, and have used something
similar a few times in the past, but now when (<argument list>) is:
(unsigned char x1, unsigned char x2, unsigned char x3,
int *y1, unsigned int *y2, int *y3)
I get the compiler message:
"warning: initialization from incompatible pointer type"
What am I doing wrong?
The problem is probably here:
int (*myfunc)();
A modern compiler is going to demand that the input parameters (arguments)
to the function (as defined in the pointer type) be compatible with the
function prototype. I could make arguments based on full prototype linkage
and so on.
Just supply the argument list and I think you'll be OK.
--
David T. Ashley (dta@xxxxxxxx)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
.
- References:
- Problem with pointer to function - what's wrong here?
- From: Charles Sullivan
- Problem with pointer to function - what's wrong here?
- Prev by Date: Re: Problem with pointer to function - what's wrong here?
- Next by Date: Re: Problem with pointer to function - what's wrong here?
- Previous by thread: Re: Problem with pointer to function - what's wrong here?
- Next by thread: Re: Problem with pointer to function - what's wrong here?
- Index(es):
Relevant Pages
|