[petsc-dev] PETSC_TRUE and PETSC_TRUTH

Barry Smith bsmith at mcs.anl.gov
Fri Sep 3 13:56:55 CDT 2010


On Sep 3, 2010, at 1:53 PM, Chetan Jhurani wrote:

> The conversation went in direction of bool and incompatibility.  Not that there
> is anything wrong with it.
> 
> My suggestion was to change only PETSC_TRUTH to something like PETSC_TRUTH_DATA
> or PETSC_TRUTH_TYPE which would not be a very inconsistent change in terms of
> nouns and it will avoid bugs due to typos.
> 
> Unlike PETSC_TRUE, PETSC_TRUTH looks like an implementation detail.  It is used
> in only three C files in the sys directory.

  The only reason for the discussion is we don't want to introduce an inconsistency between the use of truth in PetscTruth and in PETSC_TRUTH. Just changing PETSC_BOOL would be inconsistent and harder to remember and use. 

   It looks like we will switch to bool in both locations.

   
> 
> Chetan
> 
>> -----Original Message-----
>> From: petsc-dev-bounces at mcs.anl.gov [mailto:petsc-dev-bounces at mcs.anl.gov] On Behalf Of Lisandro
>> Dalcin
>> Sent: Friday, September 03, 2010 7:58 AM
>> To: For users of the development version of PETSc
>> Cc: petsc-dev
>> Subject: Re: [petsc-dev] PETSC_TRUE and PETSC_TRUTH
>> 
>> On 2 September 2010 20:02, Jed Brown <jed at 59a2.org> wrote:
>>> On Thu, 2 Sep 2010 18:08:12 -0400, Kai Germaschewski <kai.germaschewski at unh.edu> wrote:
>>>> I know that bool is not standard (in plain old C). However, as you say, it
>>>> is in C++ and C99, and in as extension in some older compilers. I have no
>>>> doubt there was a good reason to introduce the type at the time, but that
>>>> doesn't necessarily mean you have to keep carrying it along forever, in
>>>> particular if you're changing the wording anyway. The one issue I do see is
>>>> if an existing application has, e.g., typedef int bool; while the petsc
>>>> header says typedef enum { false, true } bool;
>>> 
>>> FWIW, neither of these are valid definitions, they have a different size
>>> than the bool in stdbool.h (technically the size of the enum is
>>> implementation-dependent, but it is almost certainly the same size as
>>> int, while bool is 1 byte).
>>> 
>>> Jed
>>> 
>> 
>> 
>> 1) Is bool 1 byte in OS X?
>> 
>> 2) Microsoft compilers do not support C99, then there is no bool
>> AFAIK, it would need emulation (with a char?)
>> 
>> 3) How a change would impact Fortran?
>> 
>> 4) What about cross-platform I/O compatibility?
>> 
>> 5) How to communicate them with MPI(-1) in possibly heterogeneous environments?
>> 
>> For all these reasons and others I'm likely missing, I think
>> PetscTruth should be an enum (it will likely match an int in almost
>> all platforms, even in C++), and perhaps It would be better to call it
>> PetscBool.  Other way would be typedef'inf it as a 'unsigned char' and
>> #define TRUE and FALSE, but not sure how to handle Fortran. Using a
>> (unsigned) char would be nice because of sizeof 1, and there are no
>> endian issues, thus simplifying I/O.
>> 
>> 
>> --
>> Lisandro Dalcin
>> ---------------
>> CIMEC (INTEC/CONICET-UNL)
>> Predio CONICET-Santa Fe
>> Colectora RN 168 Km 472, Paraje El Pozo
>> Tel: +54-342-4511594 (ext 1011)
>> Tel/Fax: +54-342-4511169
> 




More information about the petsc-dev mailing list