[petsc-dev] #define FORTRANNULLFUNCTION(a) (((void(*)(void))(PETSC_UINTPTR_T)a) == PETSC_NULL_FUNCTION_Fortran)

Barry Smith bsmith at mcs.anl.gov
Thu Nov 21 22:26:28 CST 2013


  Jed,

    It seems this PETSC_UINTPTR_T here is allowing one to cast a void * to a function pointer without generating a warning/error? Is this correct code? Why does it even work?

    I’m trying to get rid of the last of the "casting object pointer to function pointer" warning messages out of PETSc but still get a truck load with 

#define CHKFORTRANNULLFUNCTION(a)  \
  if (FORTRANNULLSCALAR(a) || FORTRANNULLDOUBLE(a) || FORTRANNULLREAL(a) || FORTRANNULLINTEGER(a) || FORTRANNULLOBJECT(a)) { \
    PetscError(PETSC_COMM_SELF,__LINE__,"fortran_interface_unknown_file",__FILE__,PETSC_ERR_ARG_WRONG,PETSC_ERROR_INITIAL, \
    "Use PETSC_NULL_FUNCTION"); *ierr = 1; return; } \
  else if (FORTRANNULLFUNCTION(a)) { a = NULL; }


because each of the FORTRANNULLXXX() tests  cast the function pointer a to an object pointer. Can I instead use the PETSC_UINTPTR_T  trick to cast the object pointers
 like PETSC_NULL_INTEGER_Fortran to function pointers and compare them to eliminate all the warnings?

    Thanks

   Barry




More information about the petsc-dev mailing list