aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-05-24 10:03:20 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-05-25 14:12:22 +0200
commitf250572fe276f2b0a702294fb5754eb2b9e622de (patch)
tree175c113be8832c2cc1ec6845d1e0d11fa3d0da20
parentf9f7e1e3d394024484df41e3d97d6b8505810f36 (diff)
Added afb-helpers-utils.h
Added this file to some useful macros, the first one here is INT_STR_MAX that permits to get rid of a warning with gcc >= 7.2.0 Change-Id: I768d216ab5494d346d5ee6e0df66f93410bfab57 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
-rw-r--r--afb-helpers-utils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/afb-helpers-utils.h b/afb-helpers-utils.h
new file mode 100644
index 0000000..d180f08
--- /dev/null
+++ b/afb-helpers-utils.h
@@ -0,0 +1,17 @@
+#ifndef AFB_HELPERS_UTILS_H
+#define AFB_HELPERS_UTILS_H
+
+#include <limits.h>
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+/* with gcc >= 7.2.0, this macro is useful when printing an int with snprintf:
+ *
+ * char[INT_STR_MAX]; // smaller value leads to a warning
+ * snprintf(targetS, sizeof (targetS), "%d", target);
+ * */
+
+#define INT_STR_MAX sizeof(xstr(INT_MAX))
+
+#endif /* AFB_HELPERS_UTILS_H */