Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
Why aren't constexpr const scoped variables implicitly static?

(Following to this question:)

void foo() {
    constexpr const auto my_lambda = [](int z) { return z+1; };
}

Apparently, my_lambda is "not static". In what sense is it not-static, other than not officially defined to be? Why should it not be implicitly static, seeing how it seems to meet the definition?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In what sense is it not-static

Its not static in the sense that it doesn't have static storage duration. It has automatic storage duration.

For most purposes, it doesn't matter whether the storage duration is static or not because the initialisation and destruction of the object are trivial, and the storage isn't used at all. Still, this demonstrates an important difference:

auto* foo() {
    constexpr const auto my_lambda = [](int z) { return z+1; };
    return &my_lambda; // dangling pointer
}

auto* foo_static() {
    static constexpr const auto my_lambda = [](int z) { return z+1; };
    return &my_lambda; // OK
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda