473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

macros-loop? calling macros X times?

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?
Nov 14 '05 #1
2 7583
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.

Nov 14 '05 #2
Andrew Arro <ar**@arro.ru> 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
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: seberino | last post by:
I've been reading the beloved Paul Graham's "Hackers and Painters". He claims he developed a web app at light speed using Lisp and lots of macros. It got me curious if Lisp is inherently faster...
6
by: Greg Smith | last post by:
I'm sure there is a way to do this but I can't seem to find it. How do you assign a key-stroke to a macro so you can call it from the editor? What I would like to do is type...
0
by: Robert Scheer | last post by:
Hi. I have some macros recorded under MyMacros\Module1. One of these macros executes a task that already exists on a macro under Samples\Utilities, one of the group of macros installed by...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
2
by: cr113 | last post by:
I just upgraded from Office 2000 to Office 2003. My VB.NET Excel macro calls don't work any longer. Here is how I make my Excel macro call from VB.NET: Dim objExcel as Excel.Application ...
5
by: Ben | last post by:
This is a follow-on from the "Help with array/pointer segmentation fault needed" thread.. I have not been able to find much information on the rules for macros. I want to be able to call a macro...
1
by: sanjeevdivekar | last post by:
hi, i am newbie to python so i am trying to learn mod_python as my new development kit for my small web apps. i am getting strange result can anybody explain me....
20
by: copx | last post by:
Is it true that C macros are unsafe when combined with side effects even if they are "clean" e.g. could foo_macro(++c); execute "++c" multiple times even if foo_macro is "clean"? I have always...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.