True/False Dichotomy
-
Here's one I spotted in a previous life: We were working in C on protocol stacks. In every C file created by a group of contractors, we found the following statements:
#define True 0
#define False 1This was endemic throughout the code produced by this particular group of contractors. Fortunately, the product never came to be. The 2001 Tech Wreck did it in. Geoff
Professional Geek, Amateur Stage-Levelling Gauge
-
Here's one I spotted in a previous life: We were working in C on protocol stacks. In every C file created by a group of contractors, we found the following statements:
#define True 0
#define False 1This was endemic throughout the code produced by this particular group of contractors. Fortunately, the product never came to be. The 2001 Tech Wreck did it in. Geoff
Professional Geek, Amateur Stage-Levelling Gauge
Ew. While I agree that true should be zero (there are many ways of being wrong, but only one way to be correct; it's also orthogonal with strcmp), I still wouldn't do that. What we had at one place was:
#define true (0==0)
#define false (!true) -
Ew. While I agree that true should be zero (there are many ways of being wrong, but only one way to be correct; it's also orthogonal with strcmp), I still wouldn't do that. What we had at one place was:
#define true (0==0)
#define false (!true)I've started to favour this form:
#define TRUE (!0)
#define FALSE (!TRUE)But at least I put it in a header rather than within every single source file. In this case, it was in *.c. Can you say "maintenance nightmare"? And they claimed they were a CMM level 5 company, too.
Professional Geek, Amateur Stage-Levelling Gauge
modified on Wednesday, February 4, 2009 6:19 PM
-
I've started to favour this form:
#define TRUE (!0)
#define FALSE (!TRUE)But at least I put it in a header rather than within every single source file. In this case, it was in *.c. Can you say "maintenance nightmare"? And they claimed they were a CMM level 5 company, too.
Professional Geek, Amateur Stage-Levelling Gauge
modified on Wednesday, February 4, 2009 6:19 PM
The
(0==0)
may be more portable, which is what they were after. I just tried (0==0) and (!0) on two compilers and both agreed that they equal 1, but that may not always be (or have been) the case. -
The
(0==0)
may be more portable, which is what they were after. I just tried (0==0) and (!0) on two compilers and both agreed that they equal 1, but that may not always be (or have been) the case.Many C compilers (and ancient C++ compilers) don't support the
bool
type. The expression (0==0) has the advantage of having typebool
when possible andint
otherwise. -
Here's one I spotted in a previous life: We were working in C on protocol stacks. In every C file created by a group of contractors, we found the following statements:
#define True 0
#define False 1This was endemic throughout the code produced by this particular group of contractors. Fortunately, the product never came to be. The 2001 Tech Wreck did it in. Geoff
Professional Geek, Amateur Stage-Levelling Gauge
I would love to have macro-definitions in C# or Java just to break all these silly stereotypes.
#define max(a,b) (a>b ? b : a)
#define min(a,b) (a>b ? a : b)or
#define cerr (cin)
#define cout (cerr)
#define cin (cout)Aaah so confusing so sweet ... ;P
Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.