PetscTruth bool?

Lisandro Dalcin dalcinl at gmail.com
Wed Sep 24 11:27:30 CDT 2008


Barry, see this

$ cat testbool.c
#include <stdio.h>
#include <stdbool.h>
int main(){
  printf("sizeof(bool): %d\n", sizeof(bool));
  printf("sizeof(int):  %d\n", sizeof(int));
}
$ gcc testbool.c
$ a.out
sizeof(bool): 1
sizeof(int):  4

And now this:

$ cat testbool.cpp
#include <iostream>
int main(){
  std::cout << "sizeof(bool): " << sizeof(bool) << std::endl;
  std::cout << "sizeof(int): "  << sizeof(int)  << std::endl;
}
$ g++ testbool.cpp
$ a.out
sizeof(bool): 1
sizeof(int): 4

Unless I'm doing something wrong, it seems that in my system (32bits
box, FedoraCore 6) 'bool' do not  have the size of an 'int' in both C
and C++.


On Wed, Sep 24, 2008 at 12:59 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> On Sep 24, 2008, at 9:30 AM, Matthew Knepley wrote:
>
>> On Wed, Sep 24, 2008 at 8:51 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>
>>>  Since C++ has bool and C99 has bool, should PetscTruth be changed to be
>>> defined to be bool? Instead of int.
>>
>> I see the motivation, but we would have to recode any MPI usages of
>> PetscTruth
>> since we could not guarantee the size of bool.
>
>   Matt,
>
>    YOU, of all people, being pedantic :-)
>
>    Show me a single system where a bool is not an int size.
>
>   Actually, some Fortran compilers use a -1 as true (not a 1!), this is
> already
> painful and could be tricky.
>
>
>   Barry
>
>
>>
>>
>>  Matt
>>
>>>  Barry
>>>
>>> Should we go further and simply remove PetscTruth and use bool directly
>>> in
>>> its place? (logical in Fortran).
>>
>> --
>> 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
>>
>
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594




More information about the petsc-dev mailing list