Skip to content

Commit 2ddae39

Browse files
authored
Merge pull request #884 from sleeptightAnsiC/fix__build_sizeof_bool
Fix(build): replace incorrect static asserts for size(nk_bool)
2 parents 1f37b78 + 595a81f commit 2ddae39

5 files changed

Lines changed: 22 additions & 29 deletions

File tree

demo/sdl3_renderer/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@
5858
#define NK_POINTER_TYPE uintptr_t
5959
#endif
6060

61-
/* FIXME: We could also use the `bool` symbol provided by SDL,
62-
* but this is currently broken due to internal Nuklear issue, see:
63-
* https://github.com/Immediate-Mode-UI/Nuklear/issues/849
64-
* */
65-
#define NK_INCLUDE_STANDARD_BOOL
61+
/* We can reuse the `bool` symbol because SDL3 guarantees its existence */
62+
/*#define NK_INCLUDE_STANDARD_BOOL*/
6663
#ifndef NK_INCLUDE_STANDARD_BOOL
6764
#define NK_BOOL bool
6865
#endif

nuklear.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,13 @@ extern "C" {
407407
#endif
408408
#endif
409409

410+
/**< could be any type with semantic of standard bool, either equal or smaller than int */
410411
#ifndef NK_BOOL
411412
#ifdef NK_INCLUDE_STANDARD_BOOL
412413
#include <stdbool.h>
413414
#define NK_BOOL bool
414415
#else
415-
#define NK_BOOL int /**< could be char, use int for drop-in replacement backwards compatibility */
416+
#define NK_BOOL int
416417
#endif
417418
#endif
418419

@@ -443,11 +444,7 @@ NK_STATIC_ASSERT(sizeof(nk_flags) >= 4);
443444
NK_STATIC_ASSERT(sizeof(nk_rune) >= 4);
444445
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
445446
NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));
446-
#ifdef NK_INCLUDE_STANDARD_BOOL
447-
NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool));
448-
#else
449-
NK_STATIC_ASSERT(sizeof(nk_bool) >= 2);
450-
#endif
447+
NK_STATIC_ASSERT(sizeof(nk_bool) <= sizeof(int));
451448

452449
/* ============================================================================
453450
*
@@ -494,6 +491,10 @@ struct nk_nine_slice {struct nk_image img; nk_ushort l, t, r, b;};
494491
struct nk_cursor {struct nk_image img; struct nk_vec2 size, offset;};
495492
struct nk_scroll {nk_uint x, y;};
496493

494+
/* Make sure the semantic of nk_true/nk_false is compatible with nk_bool */
495+
NK_STATIC_ASSERT(!((nk_bool)0) == !(nk_false));
496+
NK_STATIC_ASSERT(!((nk_bool)1) == !(nk_true));
497+
497498
enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT};
498499
enum nk_button_behavior {NK_BUTTON_DEFAULT, NK_BUTTON_REPEATER};
499500
enum nk_modify {NK_FIXED = nk_false, NK_MODIFIABLE = nk_true};
@@ -2148,7 +2149,7 @@ NK_API void nk_window_show_if(struct nk_context *ctx, const char *name, enum nk_
21482149
* # # nk_window_show_if
21492150
* Line for visual separation. Draws a line with thickness determined by the current row height.
21502151
* ```c
2151-
* void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding)
2152+
* void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding)
21522153
* ```
21532154
*
21542155
* Parameter | Description
@@ -6128,11 +6129,7 @@ NK_STATIC_ASSERT(sizeof(nk_short) == 2);
61286129
NK_STATIC_ASSERT(sizeof(nk_uint) == 4);
61296130
NK_STATIC_ASSERT(sizeof(nk_int) == 4);
61306131
NK_STATIC_ASSERT(sizeof(nk_byte) == 1);
6131-
#ifdef NK_INCLUDE_STANDARD_BOOL
6132-
NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool));
6133-
#else
6134-
NK_STATIC_ASSERT(sizeof(nk_bool) == 4);
6135-
#endif
6132+
NK_STATIC_ASSERT(sizeof(nk_bool) <= sizeof(int));
61366133

61376134
NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384};
61386135
#define NK_FLOAT_PRECISION 0.00000000000001
@@ -30757,6 +30754,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
3075730754
/// - [y]: Minor version with non-breaking API and library changes
3075830755
/// - [z]: Patch version with no direct changes to the API
3075930756
///
30757+
/// - 2026/01/31 (4.13.2) - Fix: replace incorrect static asserts for size(nk_bool)
3076030758
/// - 2026/01/26 (4.13.1) - Fix: nk_do_property now uses NK_STRTOD via macro
3076130759
/// - Fix: failure to build from source, due to
3076230760
/// nuklear_math/util.c not declaring some functions

src/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/// - [y]: Minor version with non-breaking API and library changes
88
/// - [z]: Patch version with no direct changes to the API
99
///
10+
/// - 2026/01/31 (4.13.2) - Fix: replace incorrect static asserts for size(nk_bool)
1011
/// - 2026/01/26 (4.13.1) - Fix: nk_do_property now uses NK_STRTOD via macro
1112
/// - Fix: failure to build from source, due to
1213
/// nuklear_math/util.c not declaring some functions

src/nuklear.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ extern "C" {
184184
#endif
185185
#endif
186186

187+
/**< could be any type with semantic of standard bool, either equal or smaller than int */
187188
#ifndef NK_BOOL
188189
#ifdef NK_INCLUDE_STANDARD_BOOL
189190
#include <stdbool.h>
190191
#define NK_BOOL bool
191192
#else
192-
#define NK_BOOL int /**< could be char, use int for drop-in replacement backwards compatibility */
193+
#define NK_BOOL int
193194
#endif
194195
#endif
195196

@@ -220,11 +221,7 @@ NK_STATIC_ASSERT(sizeof(nk_flags) >= 4);
220221
NK_STATIC_ASSERT(sizeof(nk_rune) >= 4);
221222
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
222223
NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));
223-
#ifdef NK_INCLUDE_STANDARD_BOOL
224-
NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool));
225-
#else
226-
NK_STATIC_ASSERT(sizeof(nk_bool) >= 2);
227-
#endif
224+
NK_STATIC_ASSERT(sizeof(nk_bool) <= sizeof(int));
228225

229226
/* ============================================================================
230227
*
@@ -271,6 +268,10 @@ struct nk_nine_slice {struct nk_image img; nk_ushort l, t, r, b;};
271268
struct nk_cursor {struct nk_image img; struct nk_vec2 size, offset;};
272269
struct nk_scroll {nk_uint x, y;};
273270

271+
/* Make sure the semantic of nk_true/nk_false is compatible with nk_bool */
272+
NK_STATIC_ASSERT(!((nk_bool)0) == !(nk_false));
273+
NK_STATIC_ASSERT(!((nk_bool)1) == !(nk_true));
274+
274275
enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT};
275276
enum nk_button_behavior {NK_BUTTON_DEFAULT, NK_BUTTON_REPEATER};
276277
enum nk_modify {NK_FIXED = nk_false, NK_MODIFIABLE = nk_true};
@@ -1925,7 +1926,7 @@ NK_API void nk_window_show_if(struct nk_context *ctx, const char *name, enum nk_
19251926
* # # nk_window_show_if
19261927
* Line for visual separation. Draws a line with thickness determined by the current row height.
19271928
* ```c
1928-
* void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding)
1929+
* void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding)
19291930
* ```
19301931
*
19311932
* Parameter | Description

src/nuklear_internal.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ NK_STATIC_ASSERT(sizeof(nk_short) == 2);
7171
NK_STATIC_ASSERT(sizeof(nk_uint) == 4);
7272
NK_STATIC_ASSERT(sizeof(nk_int) == 4);
7373
NK_STATIC_ASSERT(sizeof(nk_byte) == 1);
74-
#ifdef NK_INCLUDE_STANDARD_BOOL
75-
NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool));
76-
#else
77-
NK_STATIC_ASSERT(sizeof(nk_bool) == 4);
78-
#endif
74+
NK_STATIC_ASSERT(sizeof(nk_bool) <= sizeof(int));
7975

8076
NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384};
8177
#define NK_FLOAT_PRECISION 0.00000000000001

0 commit comments

Comments
 (0)