Re: Defining a list of macro parameters.
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Wed, 30 Apr 2008 09:52:34 +0200
On Wed, 30 Apr 2008 08:44:57 +0100, Paul wrote:
I would like to define a list of parameters, and then pass them to a
macro. However, the compiler (gcc) only sees one parameter, rather than
expanding the definition.
That's the correct behaviour. The list of macro arguments is first split,
and then expanded. Otherwise, what would you expect
#define MACRO(foo, ...) #foo foo
#define LIST 1,2,3
MACRO(LIST, 4)
to expand to? #foo doesn't expand the parameter, so it can only be
"LIST", but foo by itself would only be 1?
Could anyone suggest a way of making this work (using the preprocessor)?
#define MyList 1,2,3,4
#define Sum(a,b,c,d) a+b+c+d
x = Sum(MyList);
#define Invoke(Macro, Args) Macro Args
Invoke(Sum, (MyList))
.
- Prev by Date: Re: K&R2 , exercise 7.6
- Next by Date: Re: K&R2 , exercise 7.6
- Previous by thread: value of the constant expression 1<<(1?1:1) < 0x9999
- Next by thread: Free YouTube Video Downloader Software
- Index(es):
Relevant Pages
|