Nico Weber
2018-06-21 18:59:21 UTC
Hi,
for strings, we currently say
extern const char kAboutBlankURL[];
in a .h file and then
const char kAboutBlankURL[] = "about:blank";
in a .cc file. This is good, we should keep doing it.
I've seen a few people instead do
constexpr char kAboutBlankURL[] = "about:blank";
in a .h file, without a .cc file. This is almost always worse: constexpr
implies const implies internal linkage, meaning every translation unit that
references kAboutBlankURL will now refer to its own local copy of the
string, and we'd have to rely on the linker to merge all these identical
strings. This is not behavior-preserving (since the standard says the
different copies of the string are supposed to live at different addresses)
and so it isn't done by default. We plan to explicitly tell the linker to
do this merging, but we don't do that today. And making the compiler do a
bunch of work that the linker then has to undo is a bit silly anyways.
There are almost no advantages to making strings constexpr, so let's keep
doing what we're currently doing.
Nico
for strings, we currently say
extern const char kAboutBlankURL[];
in a .h file and then
const char kAboutBlankURL[] = "about:blank";
in a .cc file. This is good, we should keep doing it.
I've seen a few people instead do
constexpr char kAboutBlankURL[] = "about:blank";
in a .h file, without a .cc file. This is almost always worse: constexpr
implies const implies internal linkage, meaning every translation unit that
references kAboutBlankURL will now refer to its own local copy of the
string, and we'd have to rely on the linker to merge all these identical
strings. This is not behavior-preserving (since the standard says the
different copies of the string are supposed to live at different addresses)
and so it isn't done by default. We plan to explicitly tell the linker to
do this merging, but we don't do that today. And making the compiler do a
bunch of work that the linker then has to undo is a bit silly anyways.
There are almost no advantages to making strings constexpr, so let's keep
doing what we're currently doing.
Nico
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAMGbLiELMmHUV%2BorWB6o%2B1zbQeN5w%2BPTn-VxaaPKRZrZCtdMKw%40mail.gmail.com.
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAMGbLiELMmHUV%2BorWB6o%2B1zbQeN5w%2BPTn-VxaaPKRZrZCtdMKw%40mail.gmail.com.