aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-04-24 01:07:55 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-04-24 01:07:55 +0200
commitaa3f6e0a8109ab4cc759b23c9feccff9cee4e876 (patch)
treef31e5f8541fbc02fe00a1fe2bbd030d444dd4c75 /content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc
parentbc6907e58ba86da8c30a29c98b998832c4b260d3 (diff)
downloadblog-aa3f6e0a8109ab4cc759b23c9feccff9cee4e876.tar.gz
blog-aa3f6e0a8109ab4cc759b23c9feccff9cee4e876.zip
fn-wrapper: initial version of macro magic
Diffstat (limited to 'content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc')
-rw-r--r--content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc b/content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc
new file mode 100644
index 0000000..d3f3ddf
--- /dev/null
+++ b/content/2024-04-24-fn-wrapper-macro-magic/wrap-v1.cc
@@ -0,0 +1,19 @@
+// Mock the common wrapper functionality. For the purpose of this discussion,
+// this is just a sink accepting any function argument.
+#define MOCK_WRAPPER_IMPL(ret, fn) \
+ /* do common work */ \
+ static ret wrap_##fn(...);
+
+// Utility to generate wrapper boilerplate.
+#define WRAP(ret, fn, ...) \
+ MOCK_WRAPPER_IMPL(ret, fn) \
+ \
+ extern "C" ret fn(__VA_ARGS__)
+
+WRAP(int, foo, const char* name) {
+ return wrap_foo(name);
+}
+
+WRAP(int, bar, const char* name, const char* value) {
+ return wrap_bar(name, value);
+}