Re: Problem with pointer to function - what's wrong here?



"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)


.



Relevant Pages

  • Install Curses for Bastille Install
    ... This is on a brand new install of fedora core 1. ... function 'nocbreak' returns int ... CursesFun.c:1279: warning: initialization from incompatible pointer type ...
    (perl.beginners)
  • Re: !!<====== Existence of a variable - Debunk a myth ======>!!
    ... pointer type, but you're passing it to printf as a match for an int type; ... int piA; ... Compilers are free to stop translating the code at this point if they ...
    (comp.lang.c)
  • Re: why use fprintf / size_t instead of printf/ int
    ... I could not find the original question either, ... The base address is of a pointer type, ... likely to be the the same size as a size_t, but whether any conversion ... size_t should be converted than int. ...
    (comp.lang.c)
  • Re: 0/1 Knapsack problem, what am I doing wrong
    ... pointer type, while using void* means it gets converted to whatever ... enum inttype {SCHAR, SHORT, INT, LONG, LLONG}; ... int void_func(void* pv, enum inttype code) ...
    (comp.lang.c)
  • Re: sizeof operator implementation
    ... How does C compiler gets value at ... int main{ ... casting 10 to a pointer type; might as well cast 0 and make what you're ...
    (comp.lang.c)