2

I am attempting to replace as many uses of macros in our code with proper c++17 constructs. How would I replace the following macro with a constexpr or something else?

#define FNAME "first"
#define LNAME "last"
#define NAME FNAME LNAME
const char hello[] = "hello " NAME;
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
Baruch
  • 20,590
  • 28
  • 126
  • 201
  • 1
    You can concatenate strings at compile-time, but if I were you, I'd create a small function that returns a static const string, generated the first time you call it. – HolyBlackCat Jun 13 '22 at 16:07
  • it sounds simple, but parentheses also go a long way too when combining compile-time logic – ti7 Jun 13 '22 at 16:21

0 Answers0