aboutsummaryrefslogtreecommitdiff
path: root/2025-linuxdays/funcptr.c
diff options
context:
space:
mode:
Diffstat (limited to '2025-linuxdays/funcptr.c')
-rw-r--r--2025-linuxdays/funcptr.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/2025-linuxdays/funcptr.c b/2025-linuxdays/funcptr.c
new file mode 100644
index 0000000..e4b3a83
--- /dev/null
+++ b/2025-linuxdays/funcptr.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+typedef void (*cb_t)(void *, int);
+typedef cb_t *scb_t;
+struct cb {
+ cb_t cb;
+ const char *str;
+};
+void cb(void *self, int v) {
+ struct cb *s = self;
+ printf("%s: %d\n", s->str, v);
+}
+#define callcb(CB, ...) (*(CB))(CB, __VA_ARGS__)
+
+int main(int argc, char *argv[]) {
+ struct cb c = {.cb = cb, .str = "Hello"};
+ scb_t sc = &c.cb;
+ callcb(sc, 42);
+}