Skip site navigation (1) Skip section navigation (2)

C++ and bool constants (was Re: [NOVICE] gcc 3.0.1)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Leandro Fanzone <leandro(at)hasar(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: C++ and bool constants (was Re: [NOVICE] gcc 3.0.1)
Date: 2001-08-26 06:42:00
Message-ID: 17492.998808120@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-novice
Leandro Fanzone <leandro(at)hasar(dot)com> writes:
> I have compiled PostgreSQL 7.1.2 with gcc 3.0.1, and have the following
> problem: if I include first libpq++.h before iostream, id est:
> #include <libpq++.h>
> #include <iostream>
> the compiler complains:

> This is because somewhere in PostgreSQL you have the following code:

> #ifndef true
> #define true ((bool)1)
> #endif

Yeah.  c.h has

#ifndef __cplusplus
#ifndef bool
typedef char bool;
#endif	 /* ndef bool */
#endif	 /* not C++ */

#ifndef true
#define true	((bool) 1)
#endif

#ifndef false
#define false	((bool) 0)
#endif

It's been like that for quite some time, but it's always struck me as
bizarre: if we're willing to trust a C++ compiler to provide type
bool, why would we not trust it to provide the literals true and false
as well?  ISTM the code should read

#ifndef __cplusplus

#ifndef bool
typedef char bool;
#endif

#ifndef true
#define true	((bool) 1)
#endif

#ifndef false
#define false	((bool) 0)
#endif

#endif	 /* not C++ */

Does anyone have an objection to this?

			regards, tom lane

In response to

  • gcc 3.0.1 at 2001-08-24 20:12:19 from Leandro Fanzone

Responses

pgsql-novice by date

Next:From: Justin CliftDate: 2001-08-26 07:25:00
Subject: New FAQ : FAQ: Working with Dates and Times in PostgreSQL
Previous:From: Oliver ElphickDate: 2001-08-25 17:59:31
Subject: Re: How to allow other users create databases ?

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2001-08-26 12:37:25
Subject: Re: Re: [PATCHES] Makefile.PL for Pg.so
Previous:From: Gowey, GeoffreyDate: 2001-08-26 05:50:57
Subject: RE: version 1 C-Language Functions documentation and ex ample

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group