commit 57e0cdf606bcf9a518f2cad99831133396c015fa
Author: Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Mon Jan 20 17:22:48 2025 +0100
Commit: GitHub <noreply@github.com>
CommitDate: Mon Jan 20 17:22:48 2025 +0100
declare code as C99 compliant, include stdbool.h unconditionally (#1723)
* declare code as C99 compliant, include stdbool.h unconditionally
* add a comment why `boolean` must be an `int` type
---
CMakeLists.txt | 2 ++
configure.ac | 2 +-
src/doomtype.h | 7 +++++--
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5a058d77..a7456650 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,8 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
cmake_minimum_required(VERSION 3.7.2)
project("Chocolate Doom" VERSION 3.1.0 LANGUAGES C)
+set(CMAKE_C_STANDARD 99)
+
# Autotools variables
set(top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
set(top_builddir ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/configure.ac b/configure.ac
index 7bf04169..fbc1dd51 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,7 +39,7 @@ AC_CANONICAL_HOST
orig_CFLAGS="$CFLAGS"
AM_PROG_AR
-AC_PROG_CC
+AC_PROG_CC_C99
AC_PROG_RANLIB
AC_CHECK_PROG(HAVE_PYTHON, python3, true, false)
diff --git a/src/doomtype.h b/src/doomtype.h
index 9947a070..d90cfec9 100644
--- a/src/doomtype.h
+++ b/src/doomtype.h
@@ -99,12 +99,15 @@
// standard and defined to include stdint.h, so include this.
#include <inttypes.h>
+#include <stdbool.h>
#if defined(__cplusplus) || defined(__bool_true_false_are_defined)
-// Use builtin bool type with C++.
+// The C++/C99 bool type (or _Bool that is) can only have two values:
+// 0 or 1. However, the Doom source code assumes any non-zero value
+// to evaluate to true, so we have to use an int type here.
-typedef bool boolean;
+typedef int boolean;
#else