Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions nob.h
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions tests/svlit_at_different_storages.c
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions tests/svlit_at_different_storages.stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Global SVLIT
Local SVLIT
Parameter SVLIT
3 changes: 3 additions & 0 deletions tests/svlit_at_different_storages.win32.stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Global SVLIT
Local SVLIT
Parameter SVLIT
Loading