Thanks for the alternative. 

  @jed does this mean we need to do our casting of functions like this 
everywhere?



> On Jan 11, 2022, at 12:11 PM, Zou, Ling <l...@anl.gov> wrote:
> 
> A follow up:
>  
> The compiler option '-Wno-bad-function-cast' did not work for c++. See 
> message below:
> cc1plus: error: command line option '-Wno-bad-function-cast' is valid for 
> C/ObjC but not for C++ [-Werror]
>  
> Credit to David Andrs of INL, here is an alternative solution:
>  
> MatFDColoringSetFunction(fdcoloring, 
>   (PetscErrorCode(*)(void))(void(*)(void))SNESFormFunction, this);
>  
> Thanks,
>  
> -Ling
>  
> From: petsc-users <petsc-users-boun...@mcs.anl.gov 
> <mailto:petsc-users-boun...@mcs.anl.gov>> on behalf of Zou, Ling via 
> petsc-users <petsc-users@mcs.anl.gov <mailto:petsc-users@mcs.anl.gov>>
> Date: Monday, January 10, 2022 at 9:23 PM
> To: Barry Smith <bsm...@petsc.dev <mailto:bsm...@petsc.dev>>
> Cc: PETSc <petsc-users@mcs.anl.gov <mailto:petsc-users@mcs.anl.gov>>
> Subject: Re: [petsc-users] A problem with MatFDColoringSetFunction
> 
> Thank you Barry.
>  
> -Ling
>  
> From: Barry Smith <bsm...@petsc.dev <mailto:bsm...@petsc.dev>>
> Date: Monday, January 10, 2022 at 5:13 PM
> To: Zou, Ling <l...@anl.gov <mailto:l...@anl.gov>>
> Cc: PETSc <petsc-users@mcs.anl.gov <mailto:petsc-users@mcs.anl.gov>>
> Subject: Re: [petsc-users] A problem with MatFDColoringSetFunction
> 
>  
>   This is annoying. You need to pass in a compiler flag to turn off the error 
> conditioner for casting a function pointer. It may be 
> -Wnoerror=cast-function-type just google.
>  
>   Barry
>  
>  
> 
> On Jan 10, 2022, at 4:35 PM, Zou, Ling via petsc-users 
> <petsc-users@mcs.anl.gov <mailto:petsc-users@mcs.anl.gov>> wrote:
>  
> Hi All,
>  
> I would appreciate if you could give some advice for setting the 
> ‘FormFunction’ for the MatFDColoringSetFunction function call.
> I follow what is shown in the example:
> https://petsc.org/release/src/snes/tutorials/ex14.c.html 
> <https://petsc.org/release/src/snes/tutorials/ex14.c.html>
>  
> I setup similar code structure like:
> PetscErrorCode FormFunction(SNES,Vec,Vec,void*);
> Then use it as:
> MatFDColoringSetFunction(fdcoloring, 
> (PetscErrorCode(*)(void))SNESFormFunction, this);
>  
> This works fine on my local MacOS. However, when commit it to a remote repo, 
> the compiler there gives me the following error (where warnings are treated 
> as errors):
>  
> src/base/PETScProblemInterface.C:100:67: error:
> cast between incompatible function types from
> 'PetscErrorCode (*)(SNES, Vec, Vec, void*)' {aka 'int (*)(_p_SNES*, _p_Vec*, 
> _p_Vec*, void*)'}
> to 
> 'PetscErrorCode (*)()' {aka 'int (*)()'} [-Werror=cast-function-type]
>  
> Any help is appreciated.
>  
> -Ling

Reply via email to