Skip to main content
clarify inside function to distinguish from class member static var
Link
Ciro Santilli OurBigBook.com
  • 392.5k
  • 120
  • 1.3k
  • 1.1k

Does static constexpr variable inside a function make sense?

added 54 characters in body
Source Link
David Stone
  • 29.4k
  • 17
  • 73
  • 86

If I have a variable inside a function (say, a large array), does it make sense to declare it both static and constexpr? constexpr guarantees that the array is created at compile time, so would the static be useless?

void f() { static constexpr int x [] = {   // a few thousand elements  }; // do something with the array } 

Is the static actually doing anything there in terms of generated code or semantics?

If I have a variable inside a function (say, a large array), does it make sense to declare it both static and constexpr? constexpr guarantees that the array is created at compile time, so would the static be useless?

static constexpr int x [] = { // a few thousand elements }; 

Is the static actually doing anything there in terms of generated code or semantics?

If I have a variable inside a function (say, a large array), does it make sense to declare it both static and constexpr? constexpr guarantees that the array is created at compile time, so would the static be useless?

void f() { static constexpr int x [] = {   // a few thousand elements  }; // do something with the array } 

Is the static actually doing anything there in terms of generated code or semantics?

Source Link
David Stone
  • 29.4k
  • 17
  • 73
  • 86

Does static constexpr variable make sense?

If I have a variable inside a function (say, a large array), does it make sense to declare it both static and constexpr? constexpr guarantees that the array is created at compile time, so would the static be useless?

static constexpr int x [] = { // a few thousand elements }; 

Is the static actually doing anything there in terms of generated code or semantics?