Topic: How can I tell if my compiler supports the bool type?
Author: miles@tera.com (Miles Ohlrich)
Date: 1996/06/14 Raw View
In article <4pnpmp$14oq@ausnews.austin.ibm.com>, timur@vnet.ibm.com (Timur Tabi) writes:
|> I heard about the new bool type, and I'm looking forward to having it
|> supported in the compilers I use (Watcom's and IBM's). In the meantime, I'd
|> like to use the new type in my current compilers, by doing something like:
|>
|> typedef int bool; // or maybe I should do #define bool int?
|> #define false 0
|> #define true 1
|>
|> However, if I try this on a "bool-enabled" compiler, I'll probably get some
|> errors. So what I need is something like:
|>
|> #ifndef bool
|> typedef int bool;
|> #define false 0
|> #define true 1
|> #endif
|>
|> But I don't think this is going to work. Does anyone have any suggestions?
|> I want to place these statements into a generic headerfile that will compiler
|> under both kinds of compilers.
You might look to see if your compiler vendor plans on defining a predefined
macro when bool is a keyword. In an experimental compiler that I am using, a
predefined macro, __BOOL_KEYWORD__ is defined whenever the compiler accepts bool as
a keyword (i.e. the compiler does not predefine this if you use the -no_bool option to disable
the bool keyword feature). For example, you could say something like the following:
#ifndef __BOOL_KEYWORD__
typedef int bool;
#define false 0
#define true 1
#endif
Then, when bool is not a keyword, your own definitions will be picked up. I have no idea
what Watcom and IBM are actually planning, but I imagine that it could be something
alongs these lines.
-- Miles Ohlrich
Tera Computer Company
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Larry Dalton <ldalton@venus.net>
Date: No Date Raw View
Why not:
#define FALSE 0
#define TRUE !FALSE
That should cover all possibilities...
Larry.
On Thursday, June 13, 1996, Timur Tabi wrote...
> I heard about the new bool type, and I'm looking forward to having it
> supported in the compilers I use (Watcom's and IBM's). In the meantime,
I'd
> like to use the new type in my current compilers, by doing something
like:
>
> typedef int bool; // or maybe I should do #define bool int?
> #define false 0
> #define true 1
>
> However, if I try this on a "bool-enabled" compiler, I'll probably get
some
> errors. So what I need is something like:
>
> #ifndef bool
> typedef int bool;
> #define false 0
> #define true 1
> #endif
>
> But I don't think this is going to work. Does anyone have any
suggestions?
> I want to place these statements into a generic headerfile that will
compiler
> under both kinds of compilers.
>
> --
> Timur "too sexy for my code" Tabi, timur@vnet.ibm.com
> Architect, OS/2 Warp realtime MIDI subsystem
> http://timur.austin.ibm.com/ (internal IBM only)
> http://www.shirenet.com/~crusader/Timur/ (external)
> ---
> [ comp.std.c++ is moderated. To submit articles: try just posting with
]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu
]
> [ FAQ:
http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
> [ Policy:
http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
> [ Comments? mailto:std-c++-request@ncar.ucar.edu
]
>
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Terry Thorsen <terry@millersystems.com>
Date: 1996/06/17 Raw View
Steve Willer wrote:
>
> jason@cygnus.com (Jason Merrill) wrote:
>
> >You can say
> >
> >#define bool int
> >#define false 0
> >#define true 1
> >
> >This will work on both kinds of compilers, so long as you don't try to use
> >bool in ways that won't work on the old compilers anyway.
>
> That's true to a point. But if bool is a builtin on a compiler, its
> presence will therefore have different mangling from an int.
Not to mention that using the preprocessor to define bool has unwanted
side effects. Take Visual C++ which has a header file that is
automatically included by <windows.h> that has something similar to the
following:
struct blah{
char *somestuff;
int bool;
}
Get's preprocessed into
struct blah{
char *somestuff;
int int;
}
Uggggh! I think that "#define bool int" is an abusive use of the
preproccessor. Shame on stl implementors for not at least capitalizing
bool.
Terry Thorsen
Thorsen software
terry@millersystems.com
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: gsarup@aol.com (Gsarup)
Date: 1996/06/17 Raw View
timur@vnet.ibm.com (Timur Tabi) wrote:
>However, if I try this on a "bool-enabled" compiler, I'll probably get
some
>errors. So what I need is something like:
>#ifndef bool
>typedef int bool;
>#define false 0
>#define true 1
>#endif
I have built myself a header file to help me keep code compilable despite
changes to the standard. Specifically for bool I use something like the
following:
typedef int GS_BOOL; // my initials are GS
#define GS_TRUE 1
#define GS_FALSE 0
This way when my compiler starts supporting bool I only have to change the
typedef to:
typedef bool GS_BOOL;
Regards,
Gautam
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/06/17 Raw View
Terry Thorsen <terry@millersystems.com> writes:
>Shame on stl implementors for not at least capitalizing bool.
Well, to be fair it wasn't the STL implementors (Stepanov and Lee et al)
who added `bool'; although both STL and `bool' are part of draft
standard C++, they were put there in quite separate proposals by
different people. I believe the names `bool', `true', and `false' were
chosen ahead of other names (such as BOOLEAN, Boolean, boolean, BOOL,
Bool, TRUE, FALSE, and so forth) for two reasons: partly for
consistency with other C and C++ keywords, which are all lowercase, but
also because these names were (contrary to what you implied) in less
frequent use than the alternatives.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1996/06/18 Raw View
In article <4q4tgb$duq@mulga.cs.mu.OZ.AU> fjh@mundook.cs.mu.OZ.AU
(Fergus Henderson) writes:
|> Terry Thorsen <terry@millersystems.com> writes:
|> >Shame on stl implementors for not at least capitalizing bool.
|> Well, to be fair it wasn't the STL implementors (Stepanov and Lee et al)
|> who added `bool'; although both STL and `bool' are part of draft
|> standard C++, they were put there in quite separate proposals by
|> different people. I believe the names `bool', `true', and `false' were
|> chosen ahead of other names (such as BOOLEAN, Boolean, boolean, BOOL,
|> Bool, TRUE, FALSE, and so forth) for two reasons: partly for
|> consistency with other C and C++ keywords, which are all lowercase, but
|> also because these names were (contrary to what you implied) in less
|> frequent use than the alternatives.
And in the case in question, it is worth pointing out that in the
original posting, the conflict was due to a data member called bool in
a library (not in STL). IMHO, this was the real error; even before the
standards committee adopted bool, it doesn't take much reflection to
realize that a name like this is a likely candidate for name clashes
(in user macros, for example). I have no problem with standard's
choice of name; I do have a problem with other library providers not
thinking five minutes about potential name clashes.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, tudes et r alisations en logiciel orient objet --
-- A la recherche d'une activit dans une region francophone
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: kcline@sun132.spd.dsccc.com (Kevin Cline)
Date: 1996/06/18 Raw View
In article <31C2996F.73AE@millersystems.com>,
Terry Thorsen <terry@millersystems.com> wrote:
>Not to mention that using the preprocessor to define bool has unwanted
>side effects. Take Visual C++ which has a header file that is
>automatically included by <windows.h> that has something similar to the
>following:
>
>struct blah{
> char *somestuff;
> int bool;
>}
>
>[elision by kcline]
>
>Uggggh! I think that "#define bool int" is an abusive use of the
>preproccessor. Shame on stl implementors for not at least capitalizing
>bool.
>
It's silly to say "#define bool int" instead of "typedef int bool".
But the header file shown will break no matter what, because bool
will be a reserved word.
--
Kevin Cline
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: timur@vnet.ibm.com (Timur Tabi)
Date: 1996/06/13 Raw View
I heard about the new bool type, and I'm looking forward to having it
supported in the compilers I use (Watcom's and IBM's). In the meantime, I'd
like to use the new type in my current compilers, by doing something like:
typedef int bool; // or maybe I should do #define bool int?
#define false 0
#define true 1
However, if I try this on a "bool-enabled" compiler, I'll probably get some
errors. So what I need is something like:
#ifndef bool
typedef int bool;
#define false 0
#define true 1
#endif
But I don't think this is going to work. Does anyone have any suggestions?
I want to place these statements into a generic headerfile that will compiler
under both kinds of compilers.
--
Timur "too sexy for my code" Tabi, timur@vnet.ibm.com
Architect, OS/2 Warp realtime MIDI subsystem
http://timur.austin.ibm.com/ (internal IBM only)
http://www.shirenet.com/~crusader/Timur/ (external)
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: jason@cygnus.com (Jason Merrill)
Date: 1996/06/13 Raw View
>>>>> Timur Tabi <timur@vnet.ibm.com> writes:
> I heard about the new bool type, and I'm looking forward to having it
> supported in the compilers I use (Watcom's and IBM's). In the meantime, I'd
> like to use the new type in my current compilers, by doing something like:
> typedef int bool; // or maybe I should do #define bool int?
> #define false 0
> #define true 1
> However, if I try this on a "bool-enabled" compiler, I'll probably get some
> errors. So what I need is something like:
> #ifndef bool
> typedef int bool;
> #define false 0
> #define true 1
> #endif
> But I don't think this is going to work. Does anyone have any suggestions?
> I want to place these statements into a generic headerfile that will compiler
> under both kinds of compilers.
You can say
#define bool int
#define false 0
#define true 1
This will work on both kinds of compilers, so long as you don't try to use
bool in ways that won't work on the old compilers anyway.
Jason
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/06/14 Raw View
> Timur Tabi <timur@vnet.ibm.com> writes:
>
>> [...] what I need is something like:
>
>> #ifndef bool
>> typedef int bool;
>> #define false 0
>> #define true 1
>> #endif
>
>> But I don't think this is going to work. Does anyone have any suggestions?
I suggest
#ifdef SIMULATE_BOOL
typedef int bool;
#define false 0
#define true 1
#endif
Then when compiling with an old compiler that doesn't support bool,
just compile with `-DSIMULATE_BOOL' or the equivalent.
jason@cygnus.com (Jason Merrill) writes:
>You can say
>
>#define bool int
>#define false 0
>#define true 1
>
>This will work on both kinds of compilers, so long as you don't try to use
>bool in ways that won't work on the old compilers anyway.
Not necessarily. It results in undefined behaviour according to the
draft standard, and it may well not work on new compilers.
The problem is the new compilers may come with header files that rely
on using bool in ways that won't work on the old compilers.
So even if you don't use bool in that way, doing this may break
code in the standard header files.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: willer@sq.com (Steve Willer)
Date: 1996/06/14 Raw View
jason@cygnus.com (Jason Merrill) wrote:
>You can say
>
>#define bool int
>#define false 0
>#define true 1
>
>This will work on both kinds of compilers, so long as you don't try to use
>bool in ways that won't work on the old compilers anyway.
That's true to a point. But if bool is a builtin on a compiler, its
presence will therefore have different mangling from an int. If you're
using a library that wasn't written by you and was compiled with real
bools (like, for example, OWL 5), you'll get yourself into a mess of
trouble trying to pretend it's an int. Other than the obvious linking
errors, an example is if you are overriding a library class member that
returns a 'bool' with your own function that returns an 'int' -- that's
illegal.
----
Steve Willer, SoftQuad International, Toronto ON
Work: willer@sq.com Personal: willer@interlog.com CIS: 70400,3667
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: kcline@sun132.spd.dsccc.com (Kevin Cline)
Date: 1996/06/14 Raw View
In article <4pnpmp$14oq@ausnews.austin.ibm.com>,
Timur Tabi <timur@vnet.ibm.com> wrote:
>I heard about the new bool type, and I'm looking forward to having it
>supported in the compilers I use (Watcom's and IBM's). In the meantime, I'd
>like to use the new type in my current compilers, by doing something like:
>
>typedef int bool; // or maybe I should do #define bool int?
>#define false 0
>#define true 1
>
>However, if I try this on a "bool-enabled" compiler, I'll probably get some
>errors. So what I need is something like:
>
>#ifndef bool
>typedef int bool;
>#define false 0
>#define true 1
>#endif
>
>But I don't think this is going to work. Does anyone have any suggestions?
>I want to place these statements into a generic headerfile that will compiler
>under both kinds of compilers.
The only way to do this is to test the compiler directly by attempting
to compile a tiny test program, and then build the header file depending
on the success or failure of the compile. But I am not a PC programmer,
so I don't know if there is a scripting language powerful enough to
accomplish it.
--
Kevin Cline
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]