Re: boolean in C

Lists: pgsql-hackers
From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: boolean in C
Date: 2009-07-16 10:12:34
Message-ID: 23C9499B-C96B-4484-86CA-606F3ABC7BE3@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi folks,

Today I got bitten a bit, trying to write C function for postgresql,
that also includes some of company's internal stuff. Needles to say,
our stuff defines BOOL, as well as postgresql's c.h include file.

Now, for us, we will probably change it, but is there any reason for
postgresql nowadays not to use stdbool.h, apart from fact, that no one
made an effort ? Having said that, wouldn't it be easy as just
replacing all TRUE/FALSE/BOOL with lowercase ones, and including
stdbool from c.h ?


From: Bernd Helmle <mailings(at)oopsware(dot)de>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: boolean in C
Date: 2009-07-16 11:52:59
Message-ID: DB025C53340E9FA90F3A6F9B@amenophis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

--On 16. Juli 2009 11:12:34 +0100 Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
wrote:

> Now, for us, we will probably change it, but is there any reason for
> postgresql nowadays not to use stdbool.h, apart from fact, that no one
> made an effort ? Having said that, wouldn't it be easy as just replacing
> all TRUE/FALSE/BOOL with lowercase ones, and including stdbool from c.h ?

If i remember correctly, older SUN compilers doesn't have it. Don't know if
that is still an issue yet, but we need to take care for non-gcc compilers
i think.

--
Thanks

Bernd


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: boolean in C
Date: 2009-07-16 12:11:35
Message-ID: 51E19A5C-0A7C-483C-A5AC-91D700079893@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 16 Jul 2009, at 12:52, Bernd Helmle wrote:

>
>
> --On 16. Juli 2009 11:12:34 +0100 Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl
> > wrote:
>
>> Now, for us, we will probably change it, but is there any reason for
>> postgresql nowadays not to use stdbool.h, apart from fact, that no
>> one
>> made an effort ? Having said that, wouldn't it be easy as just
>> replacing
>> all TRUE/FALSE/BOOL with lowercase ones, and including stdbool from
>> c.h ?
>
> If i remember correctly, older SUN compilers doesn't have it. Don't
> know if that is still an issue yet, but we need to take care for non-
> gcc compilers i think.
For those guys, we could just put in c.h as it is now...


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: boolean in C
Date: 2009-07-16 12:32:03
Message-ID: A458AFFE-DF1F-413E-B329-14D487381B93@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

oh, another thing.
stdbool is C99 standard feature. Not gcc extension.
Just in case, someone thinks otherwise.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: Bernd Helmle <mailings(at)oopsware(dot)de>, pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: boolean in C
Date: 2009-07-16 13:20:21
Message-ID: 23319.1247750421@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
> oh, another thing.
> stdbool is C99 standard feature.

We are still targeting C89, not C99.

Another reason not to depend on stdbool is that, so far as I can see,
the standard does not promise that type _Bool has size = 1 byte.
We have to have that because of on-disk compatibility requirements.

regards, tom lane


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bernd Helmle <mailings(at)oopsware(dot)de>, pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: boolean in C
Date: 2009-07-16 13:23:31
Message-ID: 9F52F8DE-B1F8-4B7E-B4E7-BDCE6A00D36B@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 16 Jul 2009, at 14:20, Tom Lane wrote:

> Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
>> oh, another thing.
>> stdbool is C99 standard feature.
>
> We are still targeting C89, not C99.
>
> Another reason not to depend on stdbool is that, so far as I can see,
> the standard does not promise that type _Bool has size = 1 byte.
> We have to have that because of on-disk compatibility requirements.

I think the latter is easily fixable, or forceable to be one byte.
Why C89, and not C99 ? Virtually all compilers for last 4 years have/
had C99 support.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: Bernd Helmle <mailings(at)oopsware(dot)de>, pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: boolean in C
Date: 2009-07-16 13:37:06
Message-ID: 23616.1247751426@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
> Why C89, and not C99 ? Virtually all compilers for last 4 years have/
> had C99 support.

Not everybody is running a compiler released within the last 4 years.

The short answer is that C99 doesn't appear to offer enough advantage
over C89, *for our purposes*, to justify freezing out older systems.
stdbool is a perfect example of an addition that offers precisely
zero actual functional improvement. All it would be for us is an
additional autoconf headache and portability hazard.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: boolean in C
Date: 2009-07-16 13:53:10
Message-ID: 200907161653.10284.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thursday 16 July 2009 16:23:31 Grzegorz Jaskiewicz wrote:
> On 16 Jul 2009, at 14:20, Tom Lane wrote:
> > Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
> >> oh, another thing.
> >> stdbool is C99 standard feature.
> >
> > We are still targeting C89, not C99.
> >
> > Another reason not to depend on stdbool is that, so far as I can see,
> > the standard does not promise that type _Bool has size = 1 byte.
> > We have to have that because of on-disk compatibility requirements.
>
> I think the latter is easily fixable, or forceable to be one byte.

How do you plan to do that?

> Why C89, and not C99 ? Virtually all compilers for last 4 years have/
> had C99 support.

Well, I think we want to run on systems that are older than 4 years, too.


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: boolean in C
Date: 2009-07-16 13:59:22
Message-ID: 55125FC3-5044-421B-821D-ECEAA1ADB8DE@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 16 Jul 2009, at 14:53, Peter Eisentraut wrote:

> On Thursday 16 July 2009 16:23:31 Grzegorz Jaskiewicz wrote:
>> On 16 Jul 2009, at 14:20, Tom Lane wrote:
>>> Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
>>>> oh, another thing.
>>>> stdbool is C99 standard feature.
>>>
>>> We are still targeting C89, not C99.
>>>
>>> Another reason not to depend on stdbool is that, so far as I can
>>> see,
>>> the standard does not promise that type _Bool has size = 1 byte.
>>> We have to have that because of on-disk compatibility requirements.
>>
>> I think the latter is easily fixable, or forceable to be one byte.
>
> How do you plan to do that?
by casting it to 1 byte type such as char ?
I don't think anyone will add 3rd state to boolean in stdbool, at
least not any time soon :)

And it is pretty annoying, when your product also has its own BOOLean
defined...

>
>> Why C89, and not C99 ? Virtually all compilers for last 4 years have/
>> had C99 support.
>
> Well, I think we want to run on systems that are older than 4 years,
> too.

Sure, but that's probably less than 1% of all systems.
The 4 years was a guess, I think its much more than that.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: boolean in C
Date: 2009-07-16 14:17:51
Message-ID: 6061.1247753871@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
> On 16 Jul 2009, at 14:53, Peter Eisentraut wrote:
>>>> the standard does not promise that type _Bool has size = 1 byte.
>>>> We have to have that because of on-disk compatibility requirements.

>>> I think the latter is easily fixable, or forceable to be one byte.

>> How do you plan to do that?

> by casting it to 1 byte type such as char ?

That's hardly going to improve readability for anyone. Also, it will
flat out not work for the catalog struct declarations. When we say
"bool relhasindex;" the compiler had better think that that's a
one-byte field.

> And it is pretty annoying, when your product also has its own BOOLean
> defined...

IOW you're not using stdbool either?

regards, tom lane


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: boolean in C
Date: 2009-07-16 14:32:49
Message-ID: D1C736DE-E48F-418B-8D41-DFAF9F299C82@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 16 Jul 2009, at 15:17, Tom Lane wrote:

> Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
>
> That's hardly going to improve readability for anyone. Also, it will
> flat out not work for the catalog struct declarations. When we say
> "bool relhasindex;" the compiler had better think that that's a
> one-byte field.

Sure, but I would certainly hope, there's not too many places where
you actually convert it from disc representation, to internal and vice
versa.

>
>> And it is pretty annoying, when your product also has its own BOOLean
>> defined...
>
> IOW you're not using stdbool either?

Well, saying that I don't is quite an overstatement. It was decided
long before I started working for that customer, and is full of
problems like that. But still,
it would be nice for postgresql to at least not cause problems like
that. Having said that, I will probably fix it on customer's side, but
I wanted to see if you guys will be happy with patch that changes that
in postgresql.

thanks .


From: Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: boolean in C
Date: 2009-07-16 15:30:30
Message-ID: 1247758230.1278.14.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Grzegorz Jaskiewicz píše v čt 16. 07. 2009 v 14:59 +0100:

> >
> >> Why C89, and not C99 ? Virtually all compilers for last 4 years have/
> >> had C99 support.
> >
> > Well, I think we want to run on systems that are older than 4 years,
> > too.
>
>
> Sure, but that's probably less than 1% of all systems.
> The 4 years was a guess, I think its much more than that.

For example Solaris 8 is 9 years old and still is used in production. I
guess HP-UX is in same situation. And so on. I not able to say how many
PostgreSQL runs on them but how Tom mentioned there is no significant
reason to break old platform.

Zdenek


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: boolean in C
Date: 2009-07-16 15:42:56
Message-ID: 10356.1247758976@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:
> On 16 Jul 2009, at 15:17, Tom Lane wrote:
>> That's hardly going to improve readability for anyone. Also, it will
>> flat out not work for the catalog struct declarations. When we say
>> "bool relhasindex;" the compiler had better think that that's a
>> one-byte field.

> Sure, but I would certainly hope, there's not too many places where
> you actually convert it from disc representation, to internal and vice
> versa.

We don't "convert" --- it's expected to be the same representation.
As for not too many of them, I think grepping for references to bool
catalog fields will show you differently ...

regards, tom lane