Can a macro test
be defined so that test(a, b, c)
is replaced by test(G(a), G(b), G(c))
, and similarly for any number of arguments?
Asked
Active
Viewed 60 times
1

Eric Postpischil
- 195,579
- 13
- 168
- 312

Gari
- 183
- 7
-
Are you asking whether it is possible to define a macro `test` such that `test(a, b, c)` is replaced by `test(G(a), G(b), G(c))`? – Eric Postpischil Jan 27 '20 at 14:12
-
what is `macro` achieving when `test(G(1), G(4.00), G("Hello world"));` is passed and converted to `test(1, 4.00, "Hello world");` ? – TruthSeeker Jan 27 '20 at 14:13
-
@Eric Postpischil Yes, I want test (a, b, c) to be converted to test(G(a), G(b), G(c)) – Gari Jan 27 '20 at 14:17
-
@TruthSeeker I create a dictionary and I just want to put the arguments, and the program added a macro, I recently study C, is this possible? – Gari Jan 27 '20 at 14:21
-
When I pass arguments to test, the data types of these arguments are not known to the functions and therefore I need to convert them – Gari Jan 27 '20 at 14:24
-
@Paul Ogilvie thanks – Gari Jan 27 '20 at 14:25
-
you can indeed do `#define __test(a,b,c) test(G(a), G(b), G(c))` – TruthSeeker Jan 27 '20 at 14:26
-
@TruthSeeker thanks a lot, I'll try – Gari Jan 27 '20 at 14:27
-
1@PaulOgilvie: The text to be recognized for substitution is `test`. – Eric Postpischil Jan 27 '20 at 14:35
-
There are preprocessor hacks that can accomplish the necessary expansions for a finite limit on the number of arguments. There are a number of questions and answers on Stack Overflow dealing with this. – Eric Postpischil Jan 27 '20 at 14:36
-
@TruthSeeker I've one question, it works if we have three args, but how can I do something like this for an unlimited number of arguments – Gari Jan 27 '20 at 14:37
-
1@Andre Kampling thanks a lot, you solved my problem. – Gari Jan 27 '20 at 14:49
-
1Follow [this](https://stackoverflow.com/a/45586169/4139593) – TruthSeeker Jan 27 '20 at 15:51