[petsc-dev] removing PETSC_NULL from petsc-dev

Barry Smith bsmith at mcs.anl.gov
Wed Feb 13 07:29:40 CST 2013


On Feb 13, 2013, at 6:43 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> 
> On Thu, Feb 7, 2013 at 9:56 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> I have removed the use of PETSC_NULL from all PETSc C code. Please remember to just use NULL in PETSc source code in the future (or Karl's script will find you).
> 
> I see you changed to
> 
> #define PETSC_IGNORE NULL
> 
> but kept
> 
> #define PETSC_NULL 0
> 
> Should the second be updated to
> 
> #define PETSC_NULL NULL
> 
> because it is stricter about passing PETSC_NULL for an integer argument?

  Yes, I was hesitant to change too much at once. It is fine to change and fine to add the damn deprecated message.

  Barry

> 
> Also, we could do something like this (properly guarded, of course):
> 
> __attribute__((deprecated)) PETSC_UNUSED
> PETSC_STATIC_INLINE void PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL() {};
> #define PETSC_NULL           (PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL(),NULL)
> 
> which can be used for any compiler that supports non-static statements in declarations (everything but Sun and MSVC?) and has __attribute__((deprecated)). This produces warnings like this under Clang
> 
> ex5.c:102:36: warning: 'PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL' is deprecated [-Wdeprecated-declarations]
>   ierr       = PetscOptionsGetReal(PETSC_NULL,"-par",&user.param,NULL);CHKERRQ(ierr);
>                                    ^
> /home/jed/petsc/include/petscsys.h:387:31: note: expanded from macro 'PETSC_NULL'
> #define PETSC_NULL           (PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL(),NULL)
>                               ^
> /home/jed/petsc/include/petscsys.h:385:33: note: 'PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL' declared here
> PETSC_UNUSED static inline void PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL() {};
>                                 ^
> 1 warning generated.
> 
> and like this with GCC:
> 
> ex5.c: In function ‘main’:
> ex5.c:102:3: warning: ‘PETSC_NULL_IS_DEPRECATED_JUST_USE_NULL’ is deprecated (declared at /home/jed/petsc/include/petscsys.h:385) [-Wdeprecated-declarations]
> 
> 
> We can make the error message cleaner (but more confusing) with
> 
> __attribute__((deprecated))
> PETSC_UNUSED static inline void PETSC_NULL() {};
> #define PETSC_NULL           (PETSC_NULL(),NULL)
> 
> which produces:
> 
> ex5.c: In function ‘main’:
> ex5.c:102:3: warning: ‘PETSC_NULL’ is deprecated (declared at /home/jed/petsc/include/petscsys.h:385) [-Wdeprecated-declarations]
> 
> 
> Any sense in this stuff?




More information about the petsc-dev mailing list