[petsc-dev] Function pointer conversion: undefined behavior

Karl Rupp rupp at mcs.anl.gov
Fri Jan 25 10:26:11 CST 2013


the Nightly test results improved slightly:


However, the custom Fortran stuff in C89 logs here:


seem to be quite hard to fix:
    warning: ISO C forbids conversion of function pointer
             to object pointer type [-pedantic]

These warnings are caused by assignments of the form
   void * ptr = f;
where f is a function pointer argument:
   void (PETSC_STDCALL *f)(TS*,double*,Vec*,Vec*,void*,PetscErrorCode*)
A similar warning is obtained when assigning an instance of void* to 
such a function pointer.

As an example, let's take the following function in

void PETSC_STDCALL matfdcoloringsetfunctionts_(
    MatFDColoring *fd,
    void (PETSC_STDCALL *f)(TS*,double*,Vec*,Vec*,void*,PetscErrorCode*))
   (*fd)->ftn_func_pointer = (void*) f;

A look at MatFDColoring shows
   struct  _p_MatFDColoring{
     void    *ftn_func_pointer,*ftn_func_cntx;
so the only fix I can think of is to replace void* with e.g.
   void (*ftn_func_pointer)(void);
in order to remain in the 'function pointer world'. This is, 
nevertheless, still fairly ugly. Does anyone have a better solution for 

Best regards,

More information about the petsc-dev mailing list