By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Should We Use Macros in C++ Programming ?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
* 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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.