Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define template_function_name(type) \
- function_##type
- #define template_function_declare(type) \
- type function_##type(type a, type b) \
- { \
- return a + b; \
- }
- #define template_function_internal(type) \
- type: template_function_name(type)
- template_function_declare(int);
- template_function_declare(float);
- template_function_declare(double);
- #define function(a, b) \
- _Generic( \
- a, \
- template_function_internal(int), \
- template_function_internal(float), \
- template_function_internal(double) \
- )(a, b)
- int main(void)
- {
- printf("`int` + `int` = %d\n", function(10000, 10000));
- printf("`float` + `float` = %f\n", function((float)10000.0, (float)10000.0));
- printf("`double` + `double` = %f\n", function(10000.0, 10000.0));
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement