From 92e19d440ec0810adff029f9d502144d662e6fa4 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 17 Jul 2026 06:23:40 +0700 Subject: [PATCH] v3.10.0 - NOB_SVLIT at compile-time Co-authored-by: arcout --- nob.c | 1 + nob.h | 11 +++++++++-- tests/svlit_at_different_storages.c | 18 ++++++++++++++++++ tests/svlit_at_different_storages.stdout.txt | 3 +++ ...vlit_at_different_storages.win32.stdout.txt | 3 +++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/svlit_at_different_storages.c create mode 100644 tests/svlit_at_different_storages.stdout.txt create mode 100644 tests/svlit_at_different_storages.win32.stdout.txt diff --git a/nob.c b/nob.c index 1ae982d..acc56b7 100644 --- a/nob.c +++ b/nob.c @@ -20,6 +20,7 @@ const char *test_names[] = { "private_functions_inside_public_macros", "bytes_for_utf8", "sv_foreach", + "svlit_at_different_storages", }; #define test_names_count ARRAY_LEN(test_names) diff --git a/nob.h b/nob.h index 055a1df..2bdb16b 100644 --- a/nob.h +++ b/nob.h @@ -1,4 +1,4 @@ -/* nob - v3.9.0 - Public Domain - https://github.com/tsoding/nob.h +/* nob - v3.10.0 - Public Domain - https://github.com/tsoding/nob.h This library is the next generation of the [NoBuild](https://github.com/tsoding/nobuild) idea. @@ -947,7 +947,11 @@ NOBDEF Nob_String_View nob_sv_from_parts(const char *data, size_t count); // nob_sb_to_sv() enables you to just view Nob_String_Builder as Nob_String_View #define nob_sb_to_sv(sb) nob_sv_from_parts((sb).items, (sb).count) -#define NOB_SVLIT(lit) nob_sv_from_parts((lit), sizeof(lit)-1) +#define NOB_SVLIT(lit) (NOB_CLIT(Nob_String_View){.count = sizeof(lit)-1, .data = (lit)}) +// Generally majority of the C/C++ compilers will allow you to use NOB_SVLIT to construct global variables. +// But there are some (specifically MSVC with /TC flag enabled) that will refuse. +// For such compilers use NOB_SVLIT_STATIC instead. +#define NOB_SVLIT_STATIC(lit) {.count = sizeof(lit)-1, .data = (lit)} // printf macros for String_View #ifndef SV_Fmt @@ -2956,6 +2960,7 @@ NOBDEF char *nob_temp_running_executable_path(void) #define UNREACHABLE NOB_UNREACHABLE #define UNREACHABLEF NOB_UNREACHABLEF #define SVLIT NOB_SVLIT + #define SVLIT_STATIC NOB_SVLIT_STATIC #define UNUSED NOB_UNUSED #define ARRAY_LEN NOB_ARRAY_LEN #define ARRAY_GET NOB_ARRAY_GET @@ -3125,6 +3130,8 @@ NOBDEF char *nob_temp_running_executable_path(void) /* Revision history: + 3.10.0 (2026-07-17) Make NOB_SVLIT a bit more usable at compile-time (by @Arhcout) + Add NOB_SVLIT_STATIC for when a compiler simply refuses to accept NOB_SVLIT() at compile-time (looking at you `cl.exe /TC`) (by @rexim) 3.9.0 (2026-07-15) Add NOB_TODOF() and NOB_UNREACHABLEF() Add NOB_SVLIT() Add nob_bytes_for_utf8[] and nob_sv_utf8_len() diff --git a/tests/svlit_at_different_storages.c b/tests/svlit_at_different_storages.c new file mode 100644 index 0000000..fe2aa6b --- /dev/null +++ b/tests/svlit_at_different_storages.c @@ -0,0 +1,18 @@ +#define NOB_IMPLEMENTATION +#include "nob.h" + +String_View global_svlit = SVLIT_STATIC("Global SVLIT"); + +void param_svlit(String_View sv) +{ + printf(SV_Fmt"\n", SV_Arg(sv)); +} + +int main() +{ + String_View local_svlit = SVLIT("Local SVLIT"); + printf(SV_Fmt"\n", SV_Arg(global_svlit)); + printf(SV_Fmt"\n", SV_Arg(local_svlit)); + param_svlit(SVLIT("Parameter SVLIT")); + return 0; +} diff --git a/tests/svlit_at_different_storages.stdout.txt b/tests/svlit_at_different_storages.stdout.txt new file mode 100644 index 0000000..c9afdc1 --- /dev/null +++ b/tests/svlit_at_different_storages.stdout.txt @@ -0,0 +1,3 @@ +Global SVLIT +Local SVLIT +Parameter SVLIT diff --git a/tests/svlit_at_different_storages.win32.stdout.txt b/tests/svlit_at_different_storages.win32.stdout.txt new file mode 100644 index 0000000..ca0b4a2 --- /dev/null +++ b/tests/svlit_at_different_storages.win32.stdout.txt @@ -0,0 +1,3 @@ +Global SVLIT +Local SVLIT +Parameter SVLIT