473,401 Members | 2,068 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,401 software developers and data experts.

Should We Use Macros in C++ Programming ?

Many C++ masters recommend us not to use Macros in C++ but to use
inline functions and const .

But I think that Macros can do something inline functions and const
cannot do. It can "extend" the language in some degree. For example,
when we use MFC, there're many helper Macros without which our work
wouldn't be so easy and when I'm using Source SDK (Half-Life 2) to
develop MODs for HL2, there're alos many helpful Macros like
LINK_ENTITY_TO_CLASS, DECLARE_CLASS and so on.

So what do you think of it ?

May 7 '06 #1
3 4878
* fiNAL.Y:
Many C++ masters recommend us not to use Macros in C++ but to use
inline functions and const .

But I think that Macros can do something inline functions and const
cannot do. It can "extend" the language in some degree. For example,
when we use MFC, there're many helper Macros without which our work
wouldn't be so easy and when I'm using Source SDK (Half-Life 2) to
develop MODs for HL2, there're alos many helpful Macros like
LINK_ENTITY_TO_CLASS, DECLARE_CLASS and so on.

So what do you think of it ?


Of what?

What's the C++ question?

Please post a smallest possible example that illustrates the problem,
and compiles (unless compilation failure is the problem, in which case
it should illustrate that, and then include the error message).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 7 '06 #2

"fiNAL.Y" <so********@gmail.com> skrev i meddelandet
news:11*********************@i39g2000cwa.googlegro ups.com...
Many C++ masters recommend us not to use Macros in C++ but to use
inline functions and const .
When the Masters say "Don't use macros, they are evil!", the often
avoid mentioning the second phrase "Except when you absolutely have
to".

This is because the Masters know that their pupils cannot yet decide
when they absolutely have to.

But I think that Macros can do something inline functions and const
cannot do. It can "extend" the language in some degree. For example,
when we use MFC, there're many helper Macros without which our work
wouldn't be so easy and when I'm using Source SDK (Half-Life 2) to
develop MODs for HL2, there're alos many helpful Macros like
LINK_ENTITY_TO_CLASS, DECLARE_CLASS and so on.

So what do you think of it ?


The fact that macros can do things that inline functions cannot, is
both a blessing (sometimes) and a curse (often). Why use a sledge
hammer, when a smaller tool will do?

const int x = 42;

supplies a value x, that respects scoping, and can be redefined in an
inner scope, like in void f(int x).

On the other hand

#define x 42

will replace all x's everywhere, including in void f(int x). Is that
useful?
Bo Persson
May 7 '06 #3
of course,use macros too much is not a good thing,because there are
other thing can do better,but macros can do something very well and
any other can't do,for example #ifndef and so on.
so wo must use macros where iit must be!

May 7 '06 #4

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
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...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
43
by: Sensei | last post by:
Hi! I'm thinking about a good programming style, pros and cons of some topics. Of course, this has nothing to do with indentation... Students are now java-dependent (too bad) and I need some...
25
by: Dave | last post by:
I want to spend two minutes on my soapbox. I love C#. I am so productive in it it's ridiculous. But it's so easy to write code that uses poor design principles. Example: just making...
47
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web...
56
by: valentin tihomirov | last post by:
{ int i = 2; } int i = 1; There is no 'i' defined in the 'parent' context from the moment of declaration on. So what is the problem? They tell us they pursue language simplicity. The rule "do...
92
by: ureuffyrtu955 | last post by:
Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in google, emule, many results are not programming...
20
by: timmg | last post by:
You know, I've had so much fun reading the thread on lookup field's subservience to the Dark One that I thought I'd provoke another, ah, polite discussion on the topic of Macros. I've always...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.