double pointer to function
Chris Torek
chris at mimsy.UUCP
Mon Aug 8 08:05:12 AEST 1988
In article <107 at cyclopes.UUCP> stergios at athsys.uucp (Stergios Marinopoulos)
writes:
>Can anyone figure out why the following code does not compile
>correctly? The first ?/: pair makes cc (sun 3.4) complain ....
>[(This is] the ouput of a C++ translator [).]
Sun's compiler is correct to complain. Retaining only the relevant
code, and deleting various unnecessary parentheses:
>struct A { int (**A_tablePtr)(); };
> struct A *this ;
> void *pmf ;
> extern int flag ;
> flag ? *(void (**)())pmf :
> this->A_tablePtr[(unsigned int)*(void (**)())pmf) - 1]
Examine the types of the objects on each side of the `:':
*(void (**)())pmf =>
cast pmf to
pointer to pointer to function returning void
then indirect, so type is
pointer to function returning void
this->A_tablePtr[ <horrible unsigned-int-valued expression> ] =>
subscript (indirect) an object of type
pointer to pointer to function returning int
so type is
pointer to function returning int
Both are pointers to functions, but one returns void, the other int.
For the expressions to be compatible, either the ?: line must read
flag ? *(int (**)())pmf : <original rhs>
or the delcaration of `struct A' must read
struct A { void (**A_tablePtr)(); };
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list