You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cpp
constfrom aconstobject, only from aconst X*which points to anX. But that's not the point; the point is that automatic objects cannot have static addresses. As I said,constexprceases to be meaningful once the compilation is finished, so there is nothing to cast away (and quite possibly nothing at all, because the object is not even guaranteed to exist at runtime.)staticandconstexprbut explain that they are orthogonal and independent, doing different things. You then mention a reason to NOT combine the two since it would ignore ODR-usage (which seems useful). Oh and I still don't see why static should be used with constexpr since static is for runtime stuff. You never explained why static with constexpr is important.static constexpr(it prevents the constant array from having to be recreated on every function call), but I tweaked some words which might make it clearer. Thanks.constexprconstant variable is only used in compile-time contexts and never needed at runtime, thenstaticmakes no sense, since by the point you get to the runtime, the value has been effectively "inlined". However, ifconstexpris used in runtime contexts (in other words, theconstexprwould need to be converted toconstimplicitly, and available with a physical address for runtime code) it will wantstaticto ensure ODR compliance, etc. That is my understanding, at least.static constexpr int foo = 100;. There is no reason why the compiler couldn't substitute usage offooeverywhere for literal100, unless code were doing something like&foo. Sostaticonfoohas no usefulness in this case sincefoodoesn't exist at runtime. Again all up to the compiler.