+ SG10 This pattern is principally used for global variables, for which placeholders are not allowed, so I doubt this would be useful. That being said, I defer to SG10 call, I'm happy to add one if people think it would have use cases.
Thanks! On Wed, Jun 14, 2023 at 10:33 PM Christof Meerwald <[email protected]> wrote: > Not sure how widespread these workarounds are, but there are > stackoverflow questions related to this: > > > https://stackoverflow.com/questions/10379691/creating-macro-using-line-for-different-variable-names > > https://stackoverflow.com/questions/1082192/how-to-generate-random-variable-names-in-c-using-macros > https://stackoverflow.com/questions/461062/c-anonymous-variables > > (and I think I have seen real-world code using these workarounds) > > So I think the use case for a feature-test macro would be something > like this: > > #ifndef __unnamed_placeholder > #define CONCAT2(a, b) a ## b > #define CONCAT(a, b) CONCAT2(a, b) > #ifdef __COUNTER__ > #define _ CONCAT(placeholder, __COUNTER__) > #else > #define _ CONCAT(placeholder, __LINE__) > #endif > #endif > > void f() > { > int _ = 1; > int _ = 2; > } > > > Christof > > -- > > https://cmeerw.org sip:cmeerw at cmeerw.org > mailto:cmeerw at cmeerw.org xmpp:cmeerw at cmeerw.org >
-- SG10 mailing list [email protected] https://lists.isocpp.org/mailman/listinfo.cgi/sg10
