Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > macros-loop? calling macros X times?

Reply
Thread Tools

macros-loop? calling macros X times?

 
 
Andrew Arro
Guest
Posts: n/a
 
      07-23-2004
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?
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      07-23-2004
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.

 
Reply With Quote
 
 
 
 
S.Tobias
Guest
Posts: n/a
 
      07-24-2004
Andrew Arro <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macros within function-like macros? Anthony de Almeida Lopes C Programming 13 12-27-2005 08:38 PM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros Michael T. Babcock Python 0 11-03-2003 01:54 PM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments