Barry Smith <[email protected]> writes: > 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 think it is not strictly compliant because there is no guarantee that
function pointers are even the same size as normal pointers. I don't
actually know of an architectures that does that, however, and this
particular use doesn't depend on being able to cast both ways, just that
there be no false collisions.
> 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?
Or cast both sides to uintptr_t for the comparison.
pgp5PwsawBpkY.pgp
Description: PGP signature
