473,625 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best Place to Define TRUE/FALSE

Where is the best place to define TRUE and FALSE?

Are they in any of the standard include files, ever?

Do any standards apply?

What I've traditionally done is something like:

#ifndef (TRUE)
#define TRUE (1)
#endif

(and same for FALSE).

But is there a "standard place" or a standard way of thinking about these?
------------------------------------------------------------
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jan 14 '07 #1
71 33183
David T. Ashley wrote:
Where is the best place to define TRUE and FALSE?

Are they in any of the standard include files, ever?

Do any standards apply?

What I've traditionally done is something like:

#ifndef (TRUE)
#define TRUE (1)
#endif

(and same for FALSE).

But is there a "standard place" or a standard way of thinking about these?
No, it's each to his/her own, unless you use C99.
------------------------------------------------------------
Please trim this to two dashes, newsreaders look for a line "--<cr>" as
a signature separator.

--
Ian Collins.
Jan 14 '07 #2

"David T. Ashley" <dt*@e3ft.comwr ote in message
news:J8******** *************** *******@giganew s.com...
Where is the best place to define TRUE and FALSE?

Are they in any of the standard include files, ever?

Do any standards apply?

What I've traditionally done is something like:

#ifndef (TRUE)
#define TRUE (1)
#endif

(and same for FALSE).

But is there a "standard place" or a standard way of thinking about these?
It's in stdbool.h . We just looked at it.
news:12******** *****@corp.supe rnews.com...
LS
Jan 14 '07 #3

David T. Ashley wrote:
Where is the best place to define TRUE and FALSE?
In your own headers.
Are they in any of the standard include files, ever?
AFAICT, no. The C standard doesn't define them
Do any standards apply?
Only to the extent that they delimit what must be in the standard
headers.
What I've traditionally done is something like:

#ifndef (TRUE)
#define TRUE (1)
#endif
O....K.....

If you are going that route, then might I suggest
#ifndef FALSE
#define FALSE (0)
#define TRUE (!(FALSE))
#endif
?

Jan 14 '07 #4
"Ian Collins" <ia******@hotma il.comwrote in message
news:50******** ******@mid.indi vidual.net...
David T. Ashley wrote:
>Where is the best place to define TRUE and FALSE?

Are they in any of the standard include files, ever?

Do any standards apply?

What I've traditionally done is something like:

#ifndef (TRUE)
#define TRUE (1)
#endif

(and same for FALSE).

But is there a "standard place" or a standard way of thinking about
these?

No, it's each to his/her own, unless you use C99.
>------------------------------------------------------------
Please trim this to two dashes, newsreaders look for a line "--<cr>" as
a signature separator.

--
Ian Collins.
OK, done. Just out of curiousity, which newsreader and platform are you
using?

--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jan 14 '07 #5
2007-01-14 <J8************ *************** ***@giganews.co m>,
David T. Ashley wrote:
Where is the best place to define TRUE and FALSE?

Are they in any of the standard include files, ever?
stdbool.h defines true and false in c99.
Jan 14 '07 #6
"Lew Pitcher" <lp******@sympa tico.cawrote in message
news:11******** *************@5 1g2000cwl.googl egroups.com...
>
If you are going that route, then might I suggest
#ifndef FALSE
#define FALSE (0)
#define TRUE (!(FALSE))
#endif
I'm not sure that this is advantageous over FALSE=0, TRUE=1. Any
advantages?

Also, I think the tests used are more significant.

This:

<begin>
if (x==FALSE)
...
else if (x==TRUE)
...
<end>

would seem to lead to trouble. In fact, maybe defining TRUE is a bad idea
.... every test should be either ==FALSE or != FALSE.
--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jan 14 '07 #7

"Lew Pitcher" <lp******@sympa tico.cawrote in message
news:11******** *************@5 1g2000cwl.googl egroups.com...
>
David T. Ashley wrote:
>Where is the best place to define TRUE and FALSE?

In your own headers.
>Are they in any of the standard include files, ever?

AFAICT, no. The C standard doesn't define them
[snip]
I think that this is an example of a statement that was true in '89 but
false in '99 . I've heard rumors about long, impassioned battles about '89
vs '99, but I've never read them. I believe that the leading proponent of
the merits of the 89 standard is Richard Heathfield, but I have not read
what he has to say categorically.

It would seem that forcing the existence of stdbool.h and with it
interoperabilit y with common C extensions would be a good thing. LS
Jan 14 '07 #8
David T. Ashley wrote:
>>--
Ian Collins.
You should also set you reader to trim other people's signatures.
>
OK, done. Just out of curiousity, which newsreader and platform are you
using?
Mozilla/Solaris.

--
Ian Collins.
Jan 14 '07 #9
Ian Collins <ia******@hotma il.comwrites:
David T. Ashley wrote:
[...]
>------------------------------------------------------------
Please trim this to two dashes, newsreaders look for a line "--<cr>" as
a signature separator.
The standard signature separator is a line consisting of two dashes
and a space: "-- ". (Both of you have this right.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 14 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.