From 0a71f39cf6c947f3f99355e87095deb59ece45a2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czarnota Date: Thu, 18 Jul 2024 19:20:49 +0200 Subject: [PATCH] stb_ds: Make STBDS_OFFSETOF() return size_t Current implementation of STBDS_OFFSETOF() produces a warning when using shdel(). :error: implicit conversion changes signedness: 'long' to 'size_t' (aka 'unsigned long') [-Werror,-Wsign-conversion] if (!shdel(console->index_entries, entry->key)) This is observed on Apple clang version 15.0.0 (clang-1500.3.9.4). This happens because the difference between pointers is ptrdiff_t not size_t. A cast to size_t fixes the problem. --- stb_ds.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_ds.h b/stb_ds.h index e84c82d1d5..9c83698489 100644 --- a/stb_ds.h +++ b/stb_ds.h @@ -529,7 +529,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode); #define STBDS_ADDRESSOF(typevar, value) &(value) #endif -#define STBDS_OFFSETOF(var,field) ((char *) &(var)->field - (char *) (var)) +#define STBDS_OFFSETOF(var,field) ((size_t)((char *) &(var)->field - (char *) (var))) #define stbds_header(t) ((stbds_array_header *) (t) - 1) #define stbds_temp(t) stbds_header(t)->temp