avoiding incorrect code

Barry Smith bsmith at mcs.anl.gov
Wed Jan 14 15:49:19 CST 2009


On Jan 14, 2009, at 3:37 PM, Matthew Knepley wrote:

> On Wed, Jan 14, 2009 at 3:15 PM, Barry Smith <bsmith at mcs.anl.gov>  
> wrote:
>
>   From the PETSc developers guide
>
>  Do not use {\em if (rank == 0)} or {\em if (v == PETSC\_NULL)} or  
> {\em if (flg == PETSC\_TRUE)} or {\em if (flg == PETSC\_FALSE)}
> instead use {\em if (!rank)} or {\em if (!v)} or {\em if (flg)} or  
> {\em if (!flg)}.
>
>  There was a flag == PETSC_TRUE in PETSc 3.0.0 that wasted a lot of  
> several peoples time finding it. Come on folks, we have better  
> things to do with our time. Please avoid this incorrect usage.
>
> I am fine with 1 and 3. 4 should not matter, but I am somewhat  
> worried about 2. I thought there was no guarantee that
> NULL was actually 0, so I always check NULL.

   NOPE! The C standard specifically states that NULL is (void*)0.  
thus checking == PETSC_NULL is not needed. if (!value) is good enough  
and cleaner.

and yes 4 doesn't matter but is important to mirror the check of if  
(flg) so someone doesn't do flg == PETSC_TRUE

   Barry


>
>
>   Matt
>
>
>   Barry
> -- 
> What most experimenters take for granted before they begin their  
> experiments is infinitely more interesting than any results to which  
> their experiments lead.
> -- Norbert Wiener




More information about the petsc-dev mailing list