Git Product home page Git Product logo

Comments (10)

sylveon avatar sylveon commented on May 18, 2024 1
static constexpr char s[] = "Hello";

from calculator.

MicrosoftIssueBot avatar MicrosoftIssueBot commented on May 18, 2024

This is your friendly Microsoft Issue Bot. I created this issue automatically as requested by a team member.

from calculator.

MikeGitb avatar MikeGitb commented on May 18, 2024

What exactly do you mean by strings? const char* s ="Helllo"; is a compiletime constant. std::string on the other hand can't be made constexpr anyway.

from calculator.

danbelcher-MSFT avatar danbelcher-MSFT commented on May 18, 2024

Ideally, we move to this as standard for our string constants.

constexpr auto s = L"Hello";

from calculator.

MikeGitb avatar MikeGitb commented on May 18, 2024

Nothing against it but is there any difference between that and const auto s = L"Hello" ?

Just curious.

from calculator.

LUC18fknU7P avatar LUC18fknU7P commented on May 18, 2024

Nothing against it but is there any difference between that and const auto s = L"Hello" ?

Just curious.

L"Hello"
L Marks that the string will be always widechar.

from calculator.

MikeGitb avatar MikeGitb commented on May 18, 2024

Thanks, but my question was not about L"" vs "", but constexpr auto s = L"Hello" vs const auto s = L"Hello".

from calculator.

danbelcher-MSFT avatar danbelcher-MSFT commented on May 18, 2024

Thanks, but my question was not about L"" vs "", but constexpr auto s = L"Hello" vs const auto s = L"Hello".

I believe the only difference is that the constexpr version is available for use with other constexpr expressions during compilation, whereas the const form is not created until static are initialized at runtime.

from calculator.

MikeGitb avatar MikeGitb commented on May 18, 2024

Im pretty confident that the the "normal" const version will not cause initialization at run-time. But you are probably right about use in constexpr expressions - I haven't tried top use "nornal" global const variables in quite some time now. That's why I was asking.

from calculator.

danbelcher-MSFT avatar danbelcher-MSFT commented on May 18, 2024

I think you're right, see the doc on constant initialization.

In practice, constant initialization is performed at compile time, and pre-calculated object representations are stored as part of the program image (e.g. in the .data section). If a variable is both const and constant-initialized, its object representation may be stored in a read-only section of the program image (e.g. the .rodata section)

So is this issue even needed or should we close it? Right now I would say this is low priority and falls into the bucket of general codebase improvement/best-practices.

from calculator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.