Wed Sep 2 23:42:58 2020 UTC ()
make(1): document the value restrictions for Boolean variables

The previous lenient rule came from the sprite.h header that was not
specific to make.  To avoid confusion, only the expected values should
be stored in a Boolean variable.  To help find obvious violations and
inconsistencies, there are different possibilities for the Boolean type,
during development.

In C there is no way to actually enforce this restriction at runtime.
It would be possible in C++, but the code is not ready to be compiled
with a C++ compiler.


(rillig)
diff -r1.136 -r1.137 src/usr.bin/make/make.h

cvs diff -r1.136 -r1.137 src/usr.bin/make/make.h (expand / switch to unified diff)

--- src/usr.bin/make/make.h 2020/09/02 04:08:54 1.136
+++ src/usr.bin/make/make.h 2020/09/02 23:42:58 1.137
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: make.h,v 1.136 2020/09/02 04:08:54 rillig Exp $ */ 1/* $NetBSD: make.h,v 1.137 2020/09/02 23:42:58 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -120,39 +120,41 @@ @@ -120,39 +120,41 @@
120#define MAKE_ATTR_DEAD __volatile 120#define MAKE_ATTR_DEAD __volatile
121#else 121#else
122#define MAKE_ATTR_DEAD /* delete */ 122#define MAKE_ATTR_DEAD /* delete */
123#endif 123#endif
124 124
125#if MAKE_GNUC_PREREQ(2, 7) 125#if MAKE_GNUC_PREREQ(2, 7)
126#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) \ 126#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) \
127 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 127 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
128#else 128#else
129#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */ 129#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */
130#endif 130#endif
131 131
132/* 132/*
133 * A boolean type is defined as an integer, not an enum. This allows a 133 * A boolean type is defined as an integer, not an enum, for historic reasons.
134 * boolean argument to be an expression that isn't strictly 0 or 1 valued. 134 * The only allowed values are the constants TRUE and FALSE (1 and 0).
135 */ 135 */
136 136
137#ifdef USE_DOUBLE_BOOLEAN 137#ifdef USE_DOUBLE_BOOLEAN
138/* During development, to find type mismatches in function declarations. */ 138/* During development, to find type mismatches in function declarations. */
139typedef double Boolean; 139typedef double Boolean;
140#elif defined(USE_UCHAR_BOOLEAN) 140#elif defined(USE_UCHAR_BOOLEAN)
141/* During development, to find code that depends on the exact value of TRUE or 141/* During development, to find code that depends on the exact value of TRUE or
142 * that stores other values in Boolean variables. */ 142 * that stores other values in Boolean variables. */
143typedef unsigned char Boolean; 143typedef unsigned char Boolean;
144#define TRUE ((unsigned char)0xFF) 144#define TRUE ((unsigned char)0xFF)
145#define FALSE ((unsigned char)0x00) 145#define FALSE ((unsigned char)0x00)
 146#elif defined(USE_ENUM_BOOLEAN)
 147typedef enum { FALSE, TRUE} Boolean;
146#else 148#else
147typedef int Boolean; 149typedef int Boolean;
148#endif 150#endif
149#ifndef TRUE 151#ifndef TRUE
150#define TRUE 1 152#define TRUE 1
151#endif /* TRUE */ 153#endif /* TRUE */
152#ifndef FALSE 154#ifndef FALSE
153#define FALSE 0 155#define FALSE 0
154#endif /* FALSE */ 156#endif /* FALSE */
155 157
156#include "lst.h" 158#include "lst.h"
157#include "enum.h" 159#include "enum.h"
158#include "hash.h" 160#include "hash.h"