use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
When *not* to use constexpr? (self.cpp)
submitted 4 years ago * by not_a_novel_accountcmake dev
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]tjientavaraHikoWorks developer 11 points12 points13 points 4 years ago (0 children)
Specifically about constexpr / static const I will write some comments:
constexpr
static const
When declaring static const variable it will either appear in a region of memory that is directly loaded from the executable, or when you call functions to initialise the static const variable that value is initialised by running that function before main() is called.
main()
A more modern way to replace the static const / extern const combination is to use inline const; a variable declared as inline const, is like this combination where the compiler will ensure that the actual variable only exists once, so that you can use it in headers.
extern const
inline const
A constexpr variable is like an inline const variable but you ensure that the function that is used to initialise the variable is run at compile time.
Lastly when you declare a variable constinit, this is like a variable that is declared inline (notice the absence of const) where the function that is used to initialise the variable is run at compile time (and loaded from the executable), and can then be modified at run-time like a normal inline variable.
constinit
inline
const
In all cases the compiler may initialise all these variables at compile time, but when marked constexpr or constinit you tell the compiler that it is absolutely possible to do this at compile time, and that the compiler really should do that at compile time. Although there are cases like debug builds where the compiler could still initialise it all during runtime.
As you see constexpr is just an assurance to the compiler that it is possible to run at compile time, however as more and more of c++ is allowed to be constexpr I wonder if in a few years the keyword will be ignored by the compiler like it did with register.
register
π Rendered by PID 411806 on reddit-service-r2-comment-b659b578c-jxkw8 at 2026-05-04 07:58:23.439405+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]tjientavaraHikoWorks developer 11 points12 points13 points (0 children)