Reputation: 8606
// define 31:
#define f_Q31(x) f_Q(31,x)
#define q31_F(x) q_F(31,x)
#define CHECK_Q31(q,def) CHECK_Q(31,q,def)
// define 25:
#define f_Q25(x) f_Q(25,x)
#define q25_F(x) q_F(25,x)
#define CHECK_Q25(q,def) CHECK_Q(25,q,def)
// etc.
Can the above be generalized, like so:
#define SUPPORT_TYPE(N) something?
Adding a new type would then be a one line:
#define SUPPORT_TYPE_Q31 SUPPORT_TYPE(31)
#define SUPPORT_TYPE_Q25 SUPPORT_TYPE(25)
Upvotes: 1
Views: 223
Reputation: 140148
Preprocessor only has one pass, so you cannot generate #define
statements with other #define
statements.
You could use a small script (python comes to mind, surprisingly :)) to do what you want:
text="""// define {0}:
#define f_Q{0}(x) f_Q({0},x)
#define q{0}_F(x) q_F({0},x)
#define CHECK_Q{0}(q,def) CHECK_Q({0},q,def)
"""
for i in (25,31):
print(text.format(i))
when running this script it generates:
// define 25:
#define f_Q25(x) f_Q(25,x)
#define q25_F(x) q_F(25,x)
#define CHECK_Q25(q,def) CHECK_Q(25,q,def)
// define 31:
#define f_Q31(x) f_Q(31,x)
#define q31_F(x) q_F(31,x)
#define CHECK_Q31(q,def) CHECK_Q(31,q,def)
Upvotes: 3