macros-loop? calling macros X times?

Discussion in 'C Programming' started by Andrew Arro, Jul 23, 2004.

  1. Andrew Arro

    Andrew Arro Guest

    is it possible to make smth like a loop of macroses? i.e. i want some
    macros to be called X times, all that on the PREPROCESSOR lever

    i was trying smth like



    #define vv_0 100
    #define vv_1 101
    #define vv_2 102
    #define vv_3 103
    #define vv_4 104

    #define RUN(cur, max) \
    #if cur<max \
    printf("%d %d\n", cur, vv_ ## cur); \
    RUN((cur+1), max) \
    #endif


    but seems like #if is not possible inside of a macros?
    Andrew Arro, Jul 23, 2004
    #1
    1. Advertising

  2. Andrew Arro wrote:

    > is it possible to make smth like a loop of macroses? i.e. i want some
    > macros to be called X times, all that on the PREPROCESSOR lever
    >
    > i was trying smth like
    >
    >
    >
    > #define vv_0 100
    > #define vv_1 101
    > #define vv_2 102
    > #define vv_3 103
    > #define vv_4 104
    >
    > #define RUN(cur, max) \
    > #if cur<max \
    > printf("%d %d\n", cur, vv_ ## cur); \
    > RUN((cur+1), max) \

    ^^ Are you sure you don't want a ';' here?

    > #endif
    >
    >
    > but seems like #if is not possible inside of a macros?


    Why should you want it, anyway?

    #define RUN(cur, max) do { \
    if ( (cur) < (max)) { \
    printf("%d %d\n", (cur), vv_ ## (cur)); \
    RUN(((cur)+1), (max)); \
    }
    } while (0);

    I'd worry about the possible side effects from multiple evaluations of
    the arguments.
    Martin Ambuhl, Jul 23, 2004
    #2
    1. Advertising

  3. Andrew Arro

    S.Tobias Guest

    Andrew Arro <> wrote:
    > is it possible to make smth like a loop of macroses? i.e. i want some
    > macros to be called X times, all that on the PREPROCESSOR lever


    In general it is possible, but not straightforward, though.
    You might try and have a look at
    http://www.boost.org/libs/preprocessor/doc/index.html
    particularly at FOR and REPEAT.

    --
    Stan Tobias
    sed 's/[A-Z]//g' to email
    S.Tobias, Jul 24, 2004
    #3
    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. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    501
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  2. =?Utf-8?B?bWF2cmlja18xMDE=?=

    Forms Authentication Fails some times and not some times???

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 28, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    484
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 28, 2006
  3. djskrill
    Replies:
    9
    Views:
    691
    djskrill
    Oct 1, 2003
  4. Jack Steven
    Replies:
    2
    Views:
    418
    Chris Rebert
    Mar 9, 2009
  5. Isaac Won
    Replies:
    9
    Views:
    354
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page