Created
February 7, 2023 00:42
-
-
Save gdetor/b17c7f59e95ac0991f68c263849088a6 to your computer and use it in GitHub Desktop.
Create generic type functions in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define GENERIC_MAX( type ) \ | |
type type##_MAX(type a, type b) \ | |
{ \ | |
return (a > b) ? a : b; \ | |
} | |
int main() | |
{ | |
int ia = 5, ib = 3; | |
float fa = 3.5, fb = 8.5; | |
GENERIC_MAX(int); | |
printf("%d \n", int_MAX(ia, ib)); | |
GENERIC_MAX(float); | |
printf("%f \n", float_MAX(fa, fb)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment