[petsc-dev] PETSC_TRUE and PETSC_TRUTH

Barry Smith bsmith at mcs.anl.gov
Thu Sep 2 16:23:39 CDT 2010


On Sep 2, 2010, at 3:50 PM, Kai Germaschewski wrote:

> What is the reason for PetscTruth in the first place? Couldn't one just use bool -- from stdbool.h if available, and otherwise have petsc define it? I guess you might argue that petsc shouldn't invade non petsc-prefixed namespace, which I guess is a valid argument, on the hand one might consider that to just be petsc providing pretty much a standard type which is missing from the current environment. Or are there any Fortran-glue issues that prevent this?

   bool is not standard. There is old C, there is C99 (plus we put in PetscTruth long before C99) and there is c++ and we needed something for all of them that always works the same.

> 
> There is PETSC_FLOAT and PETSC_DOUBLE, after all, but not PetscFloat,...

   Actually there is PetscScalar and PetscReal that can become various things depending on how PETSc is built. The reason for PETSC_FLOAT and PETSC_DOUBLE is so that binary IO has names for all the basic data types.

> 
> In general, I don't like having specific versions of what's basically a standard type (I don't like PETSC_NULL, either). If you're using just one library, maybe it's not that bad, but then there's herr_t, PetscErrorCode, ... for no (obvious to me) benefit.

    The reason that PETSC_NULL exists is that in the bad old days NULL used to be defined in different include files on different machines, thus if you just stuck NULL in a routine it might not be portable on some other system (without sticking another include in), maybe this problem is gone.  PetscErrorCode is for code clarity, I think it really helps that error variables are not just declared as ints, you can see immediately what purpose it serves, that is actually the reason for several things.

   Barry

> 
> Anyway, I'd be in favor of at least a change to PetscBool.
> 
> --Kai
> 
> 
> On Thu, Sep 2, 2010 at 3:56 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> 
>  We use truth consistently PetscTruth and PETSC_TRUTH, we cannot have one be bool.
> 
>   For a long time I've wanted to replace all our uses of truth with bool but was afraid to make a change that pisses people off. That would resolve the problem.
> 
>   Barry
> 
> On Sep 2, 2010, at 2:04 PM, Satish Balay wrote:
> 
> > On Thu, 2 Sep 2010, Chetan Jhurani wrote:
> >
> >> Hi petsc-dev,
> >>
> >> This is a minor enhancement request.
> >>
> >> Using PETSC_TRUTH instead of PETSC_TRUE unintentionally will lead to
> >> unexpected results and annoying bugs.  Seems like PETSC_TRUTH is
> >> a different enum value for enumerating data types and currently equals 9.
> >>
> >> g++ does warn on comparing different enum types, but gcc does not (v4.3.0).
> >>
> >> Any possibility of changing the name of PETSC_TRUTH to something
> >> that is far away from PETSC_TRUE?
> >
> >
> > Perhaps we should use PETSC_BOOL instead of PETSC_TRUTH..
> >
> > Satish
> 
> 
> 
> 
> -- 
> Kai Germaschewski
> Assistant Professor, Dept of Physics / Space Science Center
> University of New Hampshire, Durham, NH 03824
> office: Morse Hall 245E
> phone:  +1-603-862-2912
> fax: +1-603-862-2771
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20100902/80b75c01/attachment.html>


More information about the petsc-dev mailing list