void a(void);
void b(void *);
void (*x)(void);
void c(void *p)
{
b(a);
x = p;
p = x;
}
My compiler reports the error in all three lines of function c(). The
call to b(a) is invalid, because:
Argument type 'ptr to funct ( void ) ret void' does not match parameter
type 'ptr to void'
Next two lines just report incompatible pointer types.
Well, I thought, void * is always compatible with any other pointer type
(including pointer to function) - obviously, I am wrong.
Here is the question: does it comply with ANSI standard? If not, could
anybody provide reference to corresponding section?
much thanks in advance
-------------------------------------------------------------------------
Andrej Borsenkow Fax: +7 (095) 252 01 05
SNI ITS Moscow Tel: +7 (095) 252 13 88
NERV: borsenkow.msk E-Mail: borsen...@sni.de
-------------------------------------------------------------------------
No, it's you.
>void a(void);
>void b(void *);
>
>void (*x)(void);
>
>void c(void *p)
>{
> b(a);
The required argument type is (void *). The passed argument type is
(void (*)(void)). These are not assignable to each other. Function
pointers can *NOT* be stored in a void *.
> x = p;
Same problem in reverse: x has type (void (*)(void)) and p has type
(void *). Not assignable.
> p = x;
Original problem again.
Note that:
x = a;
is fine, because the types are the same, and
x = (void (*)(void)) b;
is fine with the case, because function pointers can always be cast to
each other's types.
>Well, I thought, void * is always compatible with any other pointer type
>(including pointer to function) - obviously, I am wrong.
No, it is *NOT* compatible with pointer to function. Only with pointer
to object or incomplete type.
>Here is the question: does it comply with ANSI standard? If not, could
>anybody provide reference to corresponding section?
6.2.2.3.
--
Clive D.W. Feather | Director of Software Development | Home email:
Tel: +44 181 371 1138 | Demon Internet Ltd. | <cl...@davros.org>
Fax: +44 181 371 1037 | <cl...@demon.net> |
Written on my laptop; please observe the Reply-To address |