This shows you the differences between two versions of the page.
cpp [2012/12/20 21:15] |
cpp [2022/04/16 12:22] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <code> | ||
+ | include <iostream> | ||
+ | |||
+ | int foo1() | ||
+ | { | ||
+ | return(0); | ||
+ | } | ||
+ | |||
+ | int foo2(int val) | ||
+ | { | ||
+ | return(val); | ||
+ | } | ||
+ | |||
+ | #define PROTOTYPE_BUILDER(p_return_type, p_function_name, p_parameters) \ | ||
+ | #p_return_type" "#p_function_name"["#p_parameters | ||
+ | |||
+ | #define foo1_prototype PROTOTYPE_BUILDER(int, foo1, ()) | ||
+ | |||
+ | #define foo2_prototype PROTOTYPE_BUILDER(int, foo2, (int val)) | ||
+ | |||
+ | #define HOOK_BUILDER(p_function_name, ...) \ | ||
+ | ({ std::cout \ | ||
+ | << p_function_name##_prototype \ | ||
+ | << " = ("#__VA_ARGS__")]" << std::endl;\ | ||
+ | p_function_name(__VA_ARGS__); }) | ||
+ | |||
+ | #define foo1(...) HOOK_BUILDER(foo1, __VA_ARGS__) | ||
+ | |||
+ | #define foo2(...) HOOK_BUILDER(foo2, __VA_ARGS__) | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | foo1(); | ||
+ | return(foo2(1)); | ||
+ | } | ||
+ | |||
+ | |||
+ | /* | ||
+ | int foo1[() = ()] | ||
+ | int foo2[(int val) = (1)] | ||
+ | */ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </code> | ||