Created
January 9, 2019 19:48
-
-
Save yzchen/090ae0d2e953f2eb54971ae46f46e542 to your computer and use it in GitHub Desktop.
how to use macro to generate function names like a factory
This file contains hidden or 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
#define CONCAT_2_EXPAND(A, B) A ## B | |
#define CONCAT_2(A, B) CONCAT_2_EXPAND(A, B) | |
#define CONCAT_3_EXPAND(A, B, C) A ## B ## C | |
#define CONCAT_3(A, B, C) CONCAT_3_EXPAND(A, B, C) | |
#define Vector_(NAME) CONCAT_3(Num, Vector_, NAME) | |
#define Vector CONCAT_2(Num, Vector) | |
#define num float | |
#define Num Float | |
struct Vector | |
{ | |
num *data; | |
int n; | |
}; | |
void Vector_(add)(Vector *C, Vector *A, Vector *B) | |
{ | |
//codes | |
} | |
/* | |
real function after compilation : | |
void FloatVector_add(FloatVector *C, FloatVector *A, FloatVector *B) | |
{ | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment