aboutsummaryrefslogblamecommitdiffhomepage
path: root/content/2024-04-24-fn-wrapper-macro-magic/wrap-v2.cc
blob: 4a71635e64a607713875c5908fb4012a89e6e229 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
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))