#Why are macros looked down upon?

37 messages · Page 1 of 1 (latest)

vast forumBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

wanton gale
#

because in C++ there are basically always other ways to do it

#

like in this case, the answer is quite simple: define a real/regular function

#

also macros make your code much more difficult to debug

#

meaning that debuggers/compilers like GCC/GDB etc are often not able to give you useful or correct debug symbols in cases like that

#

why is that a problem

#

I fail to see how you fail to see that

#

you have to write them somewhere

#

what's the difference

#

octoerrfunc(bool,add); <- you wrote bool there

#

so just write it where it's supposed to go instead of using a macro

#

"I'm lazy" is an absolutely horrible reason for anything

thin wraith
#

In 99.9% of cases you don't need macros for the things your doing

lethal jetty
bitter moth
#

I use macros in very specific cases.
I wouldn't use them anywhere "because I am lazy".
To apply a canvass rule to ban them outright without listening to reason seems counter productive to me.

"Don't cross the beams, bad things will happen".
[one hour later] "Shit it's Zuul, let's cross the beams"

lethal jetty
#

there's pretty much no good use of macros in C++

bitter moth
#

Well, I disagree.

lethal jetty
#

if you find yourself reaching for macros, you're almost certainly doing smth you'd better not do

#

rare exception would be things like include guards

native zodiac
#

i just wasted 2 hours writing useless macros

#

don’t plan on going this route again tbh

#

“Useless” is a harsh word but still

#

obviously nobody says “never ever use them” but 9/10 of the time you should not use them over alternatives

#

Example: I had a macro called MAKE_ENUM_VARIANT

#

clearly… a design issue

bitter moth
#

Here's an example that people will undoubtedly deride.

In Qt, to give a QObject derived class the proper definition to allow signals and slots to bind together, the class simply has to declare Q_OBJECT.
That gives the class all the required functionality it needs to make this happen.

If that macro did not exist, every Qt developer would have to write the same boilerplate code for every class they write.

native zodiac
#

Qt is it’s own subset of C++

#

to be fair

lethal jetty
#

there shouldn't be a need to write all this boilerplate in the first place

bitter moth
#

Still, it's to me one of those perfect examples where a macro is warranted.
They do exist.

native zodiac
#

just don’t let it get to the point where it’s warranted

#

that’s kinda the idea here when it comes to cpp macros I think

native zodiac
vast forumBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] Why are macros looked down upon?