From ef843e963833d430be7c29977635e15ff53ff443 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 5 Jan 2020 11:11:26 +0000 Subject: [PATCH] New macro PTRLEN_DECL_LITERAL. This is like PTRLEN_LITERAL, but you can use it in a _declaration_ of a compile-time constant ptrlen, instead of a literal in expression context. 'const ptrlen foo = PTRLEN_DECL_LITERAL("bar");' --- misc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/misc.h b/misc.h index b9fb5721..983edaee 100644 --- a/misc.h +++ b/misc.h @@ -205,6 +205,10 @@ int string_length_for_printf(size_t); * string. */ #define PTRLEN_LITERAL(stringlit) \ TYPECHECK("" stringlit "", make_ptrlen(stringlit, sizeof(stringlit)-1)) +/* Make a ptrlen out of a compile-time string literal in a way that + * allows you to declare the ptrlen itself as a compile-time initialiser. */ +#define PTRLEN_DECL_LITERAL(stringlit) \ + { TYPECHECK("" stringlit "", stringlit), sizeof(stringlit)-1 } /* Make a ptrlen out of a constant byte array. */ #define PTRLEN_FROM_CONST_BYTES(a) make_ptrlen(a, sizeof(a))