Is it a good idea to apply some basic macros to simplify code in a large project?
Posted
by DoctorT
on Stack Overflow
See other posts from Stack Overflow
or by DoctorT
Published on 2010-04-20T16:47:53Z
Indexed on
2010/04/20
16:53 UTC
Read the original article
Hit count: 182
I've been working on a foundational c++ library for some time now, and there are a variety of ideas I've had that could really simplify the code writing and managing process. One of these is the concept of introducing some macros to help simplify statements that appear very often, but are a bit more complicated than should be necessary.
For example, I've come up with this basic macro to simplify the most common type of for loop:
#define loop(v,n) for(unsigned long v=0; v<n; ++v)
This would enable you to replace those clunky for loops you see so much of:
for (int i = 0, i < max_things; i++)
With something much easier to write, and even slightly more efficient:
loop (i, max_things)
Is it a good idea to use conventions like this? Are there any problems you might run into with different types of compilers? Would it just be too confusing for someone unfamiliar with the macro(s)?
© Stack Overflow or respective owner