This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Canonicalization of function pointers


The code snippet below demonstrates a problem in comparing a void *
to a function pointer.  I believe this is a gcc extension and is not
allowed in ISO C.

The problem is the pointers are not canonicalized which is necessary
for the comparison of function pointers on hppa[1-2]-hp-hpux and
hppa[1-2]-unknown-linux-gnu.  The latter is not implemented yet.
If f () is explitly cast to a function pointer, then both function
pointers are canonicalized.  It appears GCC converts the type of g
to void *.  This appears to be what is specified when one operand
is a pointer to an object but doesn't seem to make a lot of sense
when the operand is a function pointer.  So, should this be changed
or is the explicit cast required?

extern void *f (void);
extern int g (void);
int
foo ()
{
#if 0
  return (int (*)())f () == g;
#else
  return f () == g;
#endif
}

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]