aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc
diff options
context:
space:
mode:
Diffstat (limited to 'content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc')
-rw-r--r--content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc b/content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc
new file mode 100644
index 0000000..4a71635
--- /dev/null
+++ b/content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc
@@ -0,0 +1,14 @@
+#define MOCK_WRAPPER_IMPL(ret, fn) \
+ /* do common work */ \
+ static ret wrap_##fn(...);
+
+// Utility to generate wrapper boilerplate.
+#define WRAP(ret, fn, typed_args, args) \
+ MOCK_WRAPPER_IMPL(ret, fn) \
+ \
+ extern "C" ret fn typed_args { \
+ return wrap_##fn args; \
+ }
+
+WRAP(int, foo, (const char* name), (name))
+WRAP(int, bar, (const char* name, const char* value), (name, value))