Preprocessor

Discussion in 'C++' started by mail.dsp@gmail.com, Jun 2, 2009.

  1. Guest

    Can any body help me to define a preprocessor with variable no. of
    argument which expands as follows:

    PRE(SUNDAY, MONDAY, TUESDAY)

    expands to

    struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;

    Keep in mind that this preprocessor accept variable no. of argument.
    I tried boost preprocessor but I couldn't.
    , Jun 2, 2009
    #1
    1. Advertising

  2. * :
    > Can any body help me to define a preprocessor with variable no. of
    > argument which expands as follows:
    >
    > PRE(SUNDAY, MONDAY, TUESDAY)
    >
    > expands to
    >
    > struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;


    Don't use all uppercase except for macro names (and idiomatic usage).

    Do make sure that your code is syntactically correct.

    The above isn't.


    > Keep in mind that this preprocessor accept variable no. of argument.
    > I tried boost preprocessor but I couldn't.


    Don't, it's stupid except as a learning exercise.

    But if you were to do it, when you have progressed some from the current point
    on the learning curve, then you can easily do it, although not with the exact
    notation you exemplify above, with the Boost macro magic.

    But then you will probably not want to. :)


    Cheers & hth.,

    - Alf

    --
    Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
    No ads, and there is some C++ stuff! :) Just going there is good. Linking
    to it is even better! Thanks in advance!
    Alf P. Steinbach, Jun 2, 2009
    #2
    1. Advertising

  3. Phlip Guest

    wrote:
    > Can any body help me to define a preprocessor with variable no. of
    > argument which expands as follows:
    >
    > PRE(SUNDAY, MONDAY, TUESDAY)
    >
    > expands to
    >
    > struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;
    >
    > Keep in mind that this preprocessor accept variable no. of argument.
    > I tried boost preprocessor but I couldn't.


    use this:

    http://www.codeproject.com/KB/macros/metamacros.aspx

    However, if you need a different struct for each of a series of items, then you
    might need a better design. See if you can DRY the design up with delegation or
    inheritance of some type. ("Don't Repeat Yourself")
    Phlip, Jun 2, 2009
    #3
  4. cr88192 Guest

    <> wrote in message
    news:...
    > Can any body help me to define a preprocessor with variable no. of
    > argument which expands as follows:
    >
    > PRE(SUNDAY, MONDAY, TUESDAY)
    >
    > expands to
    >
    > struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;
    >
    > Keep in mind that this preprocessor accept variable no. of argument.
    > I tried boost preprocessor but I couldn't.


    I would have thought, as many common C++ implementations (such as GCC) share
    the (default) preprocessor with their C implementation (many of which have
    gone on to implement much of the C99 featureset), then the C99 style
    variable-argument macros should work (it will require looking into, as it is
    not "obvious"...).

    however, as others have noted, for most things there is probable not much
    use for vararg macros.

    (FWIW, I don't understand your example...).
    cr88192, Jun 2, 2009
    #4
  5. On Jun 2, 11:38 am, "cr88192" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    > > Can any body help me to define a preprocessor with variable no. of
    > > argument which expands as follows:

    >
    > > PRE(SUNDAY, MONDAY, TUESDAY)

    >
    > > expands to

    >
    > > struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;

    >
    > > Keep in mind that this preprocessor accept variable no. of argument.
    > > I tried boost preprocessor but I couldn't.

    >
    > I would have thought, as many common C++ implementations (such as GCC) share
    > the (default) preprocessor with their C implementation (many of which have
    > gone on to implement much of the C99 featureset), then the C99 style
    > variable-argument macros should work (it will require looking into, as it is
    > not "obvious"...).
    >
    > however, as others have noted, for most things there is probable not much
    > use for vararg macros.
    >
    > (FWIW, I don't understand your example...).


    varargs macros are suitable only for passing the variable arguments
    into a function which accepts variable numbers of arguments. i.e.

    #define VARARG_MACRO(arg1, arg2, ...)
    __VARARGS__

    VARARG_MACRO(1, 2, 3, 4, 5, 6, 7)

    While inside the invocation of this macro, the reserved identifier
    __VARARGS__ (or something like that, I don't remmeber exactly) will
    expand to the string literal "3, 4, 5, 6, 7"

    In the original post, he wanted to actually declare variable numbers
    of structures, so text would have to be inserted in between the
    arguments and the commas deleted, which I don't believe is possible
    with vararg macros.
    Zachary Turner, Jun 2, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris P
    Replies:
    0
    Views:
    428
    Chris P
    Oct 28, 2003
  2. The Weiss Family

    VHDL Preprocessor

    The Weiss Family, Jul 14, 2004, in forum: VHDL
    Replies:
    2
    Views:
    3,191
    The Weiss Family
    Jul 14, 2004
  3. =?Utf-8?B?SSBhbSBTYW0=?=

    C# Preprocessor

    =?Utf-8?B?SSBhbSBTYW0=?=, Mar 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,564
    =?Utf-8?B?SSBhbSBTYW0=?=
    Mar 13, 2005
  4. Replies:
    0
    Views:
    2,655
  5. Cronus
    Replies:
    1
    Views:
    641
    Paul Mensonides
    Jul 15, 2004
Loading...

Share This Page