You can't
You don't. You just redefine them wherever you need them. Latest definition will hide previous one.
Try avoiding macros. With modern C++ there are less and less things that require macro
disagreed, there are things that modern c++ is unable to do and macros can, for example stringyfication
What are you disagreeing with?
you cannot overload macros, but you can use macros with variable arguments, like: #define TEST(...) __VA_ARGS__
on avoiding macros
You should avoid them as much as possible
You may disagree as much as want but lots of developers agree with my opinion. Even the guy who invented the language https://stroustrup.com/bs_faq2.html#macro
that's an appeal to authory fallacy :P
stroustrup != the guy who invented c where macros come from
When they will add things like reflections?
you can already implement them
+ code generation
not needed
Literally, i created my telegram bot api parsing the telegram api site and writing c++ code with c++ code, it was awesome
I talked about C++, not C
that's cool, I really enjoy metaprogramming too
Read “stroustrup” again.. he says.. “So, what's wrong with using macros?” What he’s talking about is the limitations of “macros”; and it’s limited functionality. And also read the last two sentences..
Like wise you cannot use int for float/double calculations; like wise!! Every thing is precisely put to work accordingly in C/C+... modifying it otherwise you end up with “undefined behavior”.
Same way, likewise, you cannot make function(horses) act as macro(mules). 😄
Hoping for C++26
Lol, why call them mules? They are dragons, they can produce horses too 😝
He is talking about then not having a scope, not following language rule and that macros won't be improved or developed further. Language features are added to standard to all the time to make macros less and less relevant. 1 You can not debug macros. 2 Macro expansion can lead to strange side effects. 3 Macros have no "namespace", so if you have a macro that clashes with a name used elsewhere, you get macro replacements where you didn't want it, and this usually leads to strange error messages. 4 Macros may affect things you don't realize. Here are some arguments why you should avoid macros if possible: https://arne-mertz.de/2019/03/macro-evil/ https://www.reddit.com/r/cpp/comments/2kkzki/why_the_hate_for_macros/ https://scienceblogs.com/goodmath/2007/12/17/macros-why-theyre-evil I can go on and go on.
If you want to try reflection in C++ This guy created a library with his C++14 voodoo magic that supports some form of reflection https://youtu.be/abdeAew3gmQ Link to repo : https://github.com/apolukhin/magic_get
After watching his talk I understood even more how little C++ I know 😂
Macro do have types of pitfalls; they also boycott the keyword mechanism.. To overcome complex macro/debug functionality inline & virtual are practiced for compile/runtime as considered. But macros are mules, we just can’t ignore their use as important directive. Complexity at macros are problematic; such practice should be avoided, that surely is concern. —> https://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html#Macro-Pitfalls
True, someone wrote a big Macro header file that once included allowed people to write code in python inside a cpp file 😂.
* laughs in Qt *
* laughs while looking at GTK4 *
you should be crying tbh
* Laughs in SDL2 *
nahhh the tears have dried up... laughter only remains...
Обсуждают сегодня