Re: Defining a list of macro parameters.



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))
.



Relevant Pages

  • rpm and yum problems after fc2 to fc3 update
    ... I checked my rpm version ... error: Unterminated {: {lua: ... Macro %__policy_tree failed to expand ...
    (Fedora)
  • Re: Go ahead. Stop programming. This ensures you from any mistakes.
    ... It is not surprising -- in case of error, you leave resources unreleased. ... The only difference would be that the macro ... may expand to different code in release / debug versions. ... where allocation and deallocation occurs in one routine is not applicable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Sacla loop: a new loop implementation
    ... >> that the compiler must know that type in order to expand the macro. ... > through a runtime type check, the calls to FOO from within BAR need ... > and have the type information propagated again. ...
    (comp.lang.lisp)
  • Re: macro-biology
    ... > into a string that I pass to format. ... a macro can only expand into code, ... self-evaluating common lisp forms both are doable. ...
    (comp.lang.lisp)
  • Re: visibility of linux source
    ... o expand macros by clicking on them ... expand include directives ... All Macro expansions where traced and can be clicked ... click it to close the macro expansion again. ...
    (Linux-Kernel)