Issue
Often in large libraries I see code similar to the following:
#define MY_CONSTEXPR constexpr
#define MY_NOEXCEPT noexcept
#define MY_NODISCARD [[nodiscard]]
etc.
What is the purpose/benefit to creating aliases for these keywords? I see this fairly commonly but couldn't find anything regarding the practice. If I had to guess, the reason is so you can conditionally compile whether you want these keywords present in your compilation.
Solution
What is the purpose/benefit to creating aliases for these keywords? I see this fairly commonly but couldn't find anything regarding the practice. If I had to guess, the reason is so you can conditionally compile whether you want these keywords present in your compilation.
Yes, generally so. You may also see similar definitions with empty replacement text, such as
#define MY_CONST
, which cover the case where you do not want the keyword to be used.
The bigger picture is that this facilitates compatibility with various versions of the language and with various compilers. Such definitions may be written when the library is built (generally as appropriate for the toolchain being used to build it), or they may be wrapped in conditional-compilation directives that attempt to decide how to define the macros at the time that client programs are compiled.
Answered By - John Bollinger Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.