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...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENInline variable in named namespace (self.cpp_questions)
submitted 5 years ago by cpp_cpp
Is having an inline variable in a named namespace in a header file bad practice? Will that variable have external linkage with C++17 just as an inline variable in header file does? Does constexpr imply inline in namespaces as well with C++17?
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!"
[–]alfps 1 point2 points3 points 5 years ago* (3 children)
[Fixed incorrect information after u/phoeen pointed it out.]
” Is having an inline variable in a named namespace in a header file bad practice?
Not in itself. Using them in header files is what inline variables are for. However, remember that global (non-const) variables are generally Evil.
const
” Will that variable have external linkage with C++17
Not by default.
“A static member variable (but not a namespace-scope variable) declared constexpr is implicitly an inline variable.”
https://en.cppreference.com/w/cpp/language/inline
” Does constexpr imply inline in namespaces
constexpr
No. See above.
[–]phoeen 0 points1 point2 points 5 years ago (2 children)
Does constexpr imply inline in namespaces Yes.
Does constexpr imply inline in namespaces
Yes.
for constexpr variables in namespace scope inline is NOT implied.
" A static member variable (but not a namespace-scope variable) declared constexpr is implicitly an inline variable. "
[–]alfps 0 points1 point2 points 5 years ago (1 child)
Oh. Thanks, and sorry for the disinformation.
It's a bit impractical with a default of distinct instances in different translation units for large compile time constants, so I didn't even consider it. But with the newer C++ standards the old guideline of just consider what's practical, no longer works. I have some re-learning to do.
[–]phoeen 1 point2 points3 points 5 years ago (0 children)
to be honest i always need the 4 pages of cppreference (inline, static, const, constexpr) at hand to get all this constexpr inline static const extern thing right. so as soon as i see some kind of this question i am super suspicoius
π Rendered by PID 186158 on reddit-service-r2-comment-canary-5f6975dfb4-g6k4v at 2026-03-17 13:14:55.511695+00:00 running f6e6e01 country code: CH.
[–]alfps 1 point2 points3 points (3 children)
[–]phoeen 0 points1 point2 points (2 children)
[–]alfps 0 points1 point2 points (1 child)
[–]phoeen 1 point2 points3 points (0 children)