Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Macros are awesome!
When properly documented, they are actually quite nice to understand. -
@thebiochemic Macros are horrible
Not seeing the same code as the compiler sees alone is just a horrible idea.
And the worst part is using ## to append something to the macro argument.
What I've personally seen: a C++ template that needs 4 type arguments. 4 classes that are directly related to each other, but in order to not write them out all the time there's a macro that takes the typename, and generates the template with <typename, typename##thing, typename##otherthing, ...> because the naming was consistent. -
@LotsOfCaffeine macros don't do anything wrong, they just replace text with more text. I use it in a pretty similar way. In one of my C programs i have a constructor macro that is used similar to a struct declaration, but instead also adds all the necessary stuff to function as a list (with next pointer etc) and implements all the necessary functions for iterating and searching etc. for that list. I wanted to avoid conversion between to null* and back and also wanted to avoid writing all that list stuff more than once. And for exactly that purpose macros are perfectly fine (That is C mind you)
I never used a lot (or such large) macros in C++ though, since most of the time it's not necessary (because of constexpr for example).
When template stuff gets so complex, that someone saw the need to write macros for, i'm not sure if that's the macros fault. -
@LotsOfCaffeine also, a few IDEs also check the content of macros for syntax, so it's not that bad. I think CLion did it.
-
@thebiochemic Ah well in C I feel like you have to use macros for certain things, but in C++ I don't think there are many scenarios.
Problem is that the software I'm working with was written ages ago but is still actively used so I can't just go "aight lemme rewrite half of it" -
@LotsOfCaffeine Had some projects where i thought the same though: why not just refactor it all, to not suck ass, when adding new stuff to it?
I feel your pain ^^
Related Rants
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...
-
sam966911Hats off to this lady .... I would have just flipped the machine
C(++) macros will be the death of me
I sure do love working with code that was written when I was in elementary school, with all the glory of nested macros and ## to deduct type names
Love that
rant
c++
macros
help me escape this hell