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.
37 messages · Page 1 of 1 (latest)
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.
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
After static reflection/c++23 there will be almost no need for macros.
I recommend watching The Preprocessor: Everything You Need to Know and More! - Brian Ruth
https://www.youtube.com/watch?v=6KNdGnUiRBM
In 99.9% of cases you don't need macros for the things your doing
@wanton brook https://stackoverflow.com/questions/14041453/why-are-preprocessor-macros-evil-and-what-are-the-alternatives
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"
there's pretty much no good use of macros in C++
Well, I disagree.
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
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
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.
this is more a design issue with Qt than an actually good use of macros
there shouldn't be a need to write all this boilerplate in the first place
Still, it's to me one of those perfect examples where a macro is warranted.
They do exist.
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
easier said then done I realize