Fix C23 bool type being 1 byte long, while the enum bool is 4 bytes.

C23 introduced `true` and `false` as language keywords, breaking YQ2s
use of them. The first attempt to get C23 was to use the buildin `bool`
type when building in C23 mode and the classic enum based `qboolean`
in any other mode. This didn't take into acount, that `bool` is 1 byte
long, while the enum based `qboolean` is 4 bytes long. This breaks
savegames and may have impact for mods.

Fix this by always using `int` as `qboolean` and the buildin `true` and
`false` types, either in their C99 or C23 variant. This way `qboolean`
is always 4 bytes long and the newly introduced `true` and `false`
keywords don't clash.

Suggested by @DanielGibson.
This commit is contained in:
Yamagi 2025-05-11 10:11:02 +02:00
parent 3a1863f625
commit f3057fd2bc

View file

@ -35,21 +35,9 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L // C23 or newer
typedef bool qboolean;
#else
#ifdef true
#undef true
#endif
#ifdef false
#undef false
#endif
typedef enum {false, true} qboolean;
#endif
typedef int qboolean;
typedef unsigned char byte;
#ifndef NULL