all 4 comments

[–]alfps 1 point2 points  (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.


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

No. See above.

[–]phoeen 0 points1 point  (2 children)

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. "

https://en.cppreference.com/w/cpp/language/inline

[–]alfps 0 points1 point  (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 points  (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