summaryrefslogtreecommitdiff
path: root/src/include/c.h
diff options
context:
space:
mode:
authorPeter Eisentraut2018-03-23 00:42:25 +0000
committerPeter Eisentraut2018-03-23 00:42:25 +0000
commit9a95a77d9d5d3003d2d67121f2731b6e5fc37336 (patch)
tree1f43f5ff016c3ee689c09030000c4a0e8bc25842 /src/include/c.h
parent2a0faed9d7028e3830998bd6ca900be651274e27 (diff)
Use stdbool.h if suitable
Using the standard bool type provided by C allows some recent compilers and debuggers to give better diagnostics. Also, some extension code and third-party headers are increasingly pulling in stdbool.h, so it's probably saner if everyone uses the same definition. But PostgreSQL code is not prepared to handle bool of a size other than 1, so we keep our own old definition if we encounter a stdbool.h with a bool of a different size. (Among current build farm members, this only applies to old macOS versions on PowerPC.) To check that the used bool is of the right size, add a static assertions about size of GinTernaryValue vs bool. This is currently the only place that assumes that bool and char are of the same size. Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/include/c.h')
-rw-r--r--src/include/c.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/include/c.h b/src/include/c.h
index 37c0c391990..107f4f6bcd7 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -255,12 +255,21 @@
* bool
* Boolean value, either true or false.
*
- * XXX for C++ compilers, we assume the compiler has a compatible
- * built-in definition of bool.
+ * Use stdbool.h if available and its bool has size 1. That's useful for
+ * better compiler and debugger output and for compatibility with third-party
+ * libraries. But PostgreSQL currently cannot deal with bool of other sizes;
+ * there are static assertions around the code to prevent that.
+ *
+ * For C++ compilers, we assume the compiler has a compatible built-in
+ * definition of bool.
*/
#ifndef __cplusplus
+#if defined(HAVE_STDBOOL_H) && SIZEOF_BOOL == 1
+#include <stdbool.h>
+#else
+
#ifndef bool
typedef char bool;
#endif
@@ -273,6 +282,7 @@ typedef char bool;
#define false ((bool) 0)
#endif
+#endif
#endif /* not C++ */