Skip to content

Commit f3057fd

Browse files
committed
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.
1 parent 3a1863f commit f3057fd

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/header/shared.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,9 @@
3535
#include <string.h>
3636
#include <stdlib.h>
3737
#include <time.h>
38+
#include <stdbool.h>
3839

39-
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L // C23 or newer
40-
typedef bool qboolean;
41-
#else
42-
#ifdef true
43-
#undef true
44-
#endif
45-
46-
#ifdef false
47-
#undef false
48-
#endif
49-
50-
typedef enum {false, true} qboolean;
51-
#endif
52-
40+
typedef int qboolean;
5341
typedef unsigned char byte;
5442

5543
#ifndef NULL

0 commit comments

Comments
 (0)