Re: Preprocessor possibilities



Christopher Benson-Manica wrote:
> Is it possible to write a macro (in unextended C89) such that
>
> TEST( int, (1,2,3) );
>
> expands to
>
> int array[]={ 1,2,3 };
>
> ? I strongly suspect that it is not, but I don't wish to overlook a
> solution if one exists.

No, there isn't. The closest thing you can do is something like the
following which is quite ugly:

#define TEST(x,y) x array[]={y}
#define SEP ,
TEST(int, 1 SEP 2 SEP 3);

and I am not positive that even this is valid in C89.

Robert Gamble

.



Relevant Pages

  • Re: macros (was: Paul Grahams teaching style is bad}
    ... I just had not known `repeat ... ... main (int argc, char *argv) ... > example, that expands to arbitrarily nested for loops, with the depth ... > depending on the way the user uses the macro. ...
    (comp.lang.lisp)
  • Re: Preprocessor possibilities
    ... > Is it possible to write a macro (in unextended C89) such that ... > TEST(int, (1,2,3)); ... > expands to ...
    (comp.lang.c)
  • Re: Preprocessor possibilities
    ... > Is it possible to write a macro (in unextended C89) such that ... > TEST(int, (1,2,3)); ... > expands to ...
    (comp.lang.c)
  • Re: time()
    ... What does int sum ... The first #define defines a macro that expands into the macro argument ... macro that uses the first macro to change it's argument into a string. ...
    (comp.lang.c)
  • Preprocessor possibilities
    ... Is it possible to write a macro (in unextended C89) such that ... TEST(int, (1,2,3)); ... I strongly suspect that it is not, but I don't wish to overlook a ...
    (comp.lang.c)