changeset 824:562d1c61194e

val: add INT_STATIC_INITIALIZER and STATIC_INT macros Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 26 Dec 2020 10:43:42 -0500
parents ccb955138113
children 93d6c996250f
files include/jeffpc/val.h
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/include/jeffpc/val.h	Fri Oct 30 17:58:24 2020 -0400
+++ b/include/jeffpc/val.h	Sat Dec 26 10:43:42 2020 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2014-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -376,6 +376,13 @@
 #define SYM_STATIC_INITIALIZER(v)			\
 		_STATIC_STR_INITIALIZER(VT_SYM, (v))
 
+#define INT_STATIC_INITIALIZER(v)			\
+		{						\
+			.type = VT_INT,				\
+			.static_struct = true,			\
+			.i = (v),				\
+		}
+
 /* evaluates to a struct str *, so it can be used as a value */
 #define STATIC_STR(s)					\
 	({						\
@@ -390,6 +397,13 @@
 		&_s;					\
 	})
 
+/* evaluates to a struct val *, so it can be used as a value */
+#define STATIC_INT(v)					\
+	({						\
+		static struct val _v = INT_STATIC_INITIALIZER(v); \
+		&_v;					\
+	})
+
 /*
  * Allocation wrappers.  These call the identically named functions and
  * assert that there was no error.