Add compiler error when attempting to create CLAY_STRING with non literal

This commit is contained in:
Nic Barker 2025-01-10 09:20:35 +13:00
parent db04381285
commit 83ded6995e

5
clay.h
View File

@ -94,7 +94,10 @@
#define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof((s)[0])) - sizeof((s)[0]))
#define CLAY_STRING(string) (CLAY__INIT(Clay_String) { .length = CLAY__STRING_LENGTH(string), .chars = (string) })
#define CLAY__ENSURE_STRING_LITERAL(x) ("" x "")
// Note: If an error led you here, it's because CLAY_STRING can only be used with string literals, i.e. CLAY_STRING("SomeString") and not CLAY_STRING(yourString)
#define CLAY_STRING(string) (CLAY__INIT(Clay_String) { .length = CLAY__STRING_LENGTH(CLAY__ENSURE_STRING_LITERAL(string)), .chars = (string) })
static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;