79169795

Date: 2024-11-08 11:20:42
Score: 0.5
Natty:
Report link

Macros are text replacements done by the C Preprocessor; a tool that runs over your code before the compiler itself ever sees it, and consequently, before any compile-time constant expressions (such as 5+6) are evaluated.

Most importantly, the preprocessor has no notion of the language you're writing in. It doesn't know any of the syntax or semantics of either C or C++.

This is the main reason why in the C++ world, macros are generally considered "evil" (read: should be avoided unless absolutely necessary). Note that the result you want here, parsing a compile-time-evaluated number into a compile-time-evaluated string, cannot be generally achieved even in the most recent C++ standard revision. constexpr strings do exist, but they do not survive long: See Is it possible to use std::string in a constant expression?

Bottom line: Can't be done, you have to do it at runtime.

Reasons:
  • Blacklisted phrase (1): Is it possible to
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: lo-asys