[petsc-dev] PETSC_TRUE and PETSC_TRUTH

Lisandro Dalcin dalcinl at gmail.com
Fri Sep 3 08:57:52 CDT 2010


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