0

We have following macros:

#define START(x) [...]
#define FOO(x, a, b, c) [...]
#define BAR(x, a, b, c) [...]
#define END(x) [...]

We have piece of code:

START(foobar)
FOO  (foobar, 1, 2, 3)
FOO  (foobar, 0.1, 0.2, 0.3)
BAR  (foobar, 2, 3, 4)
END  (foobar)

Can we do something to let START store foobar somewhere? To xform previous into:

START(foobar)
FOO  (1, 2, 3)
FOO  (0.1, 0.2, 0.3)
BAR  (2, 3, 4)
END  ()

(something like #define FOO(x) #define VAR x)

1
  • btw, a solution would be to create a global variable, set it in START and utilize it in the FOO/BAR/END macros Commented Jul 28, 2011 at 16:30

1 Answer 1

2

What about:

definition:

#define START() [...VAR...]
#define FOO(a, b, c) [...VAR...]
#define BAR(a, b, c) [...VAR...]
#define END() [...VAR...]

usage:

#define VAR foobar
START()
FOO  (1, 2, 3)
FOO  (0.1, 0.2, 0.3)
BAR  (2, 3, 4)
END  ()
#undef VAR
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.