0

In this code, why do b or b1 not trigger an error or even a warning (with -Wall -Wextra)

Probably it would be initialized with 0s implicitly, but shouldn't this be an error, especially with constexpr?

    constexpr std::array<int, 5> a{1,2,3,4,5};
    constexpr std::array<int, 5> b{1,2,3,4};    // no error
    constexpr int b1[100]{1,2,3,4};    // no error
    // constexpr std::array<int, 5> c{1,2,3,4,5,6}; error 5 vs 6
tejas
  • 1,795
  • 1
  • 16
  • 34
  • You would prefer having to type `constexpr int b1[100]{1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};`? – 1201ProgramAlarm Jul 09 '21 at 19:12
  • @1201ProgramAlarm : I might not, but you definitely typed 96 0s there :P Good point. – tejas Jul 09 '21 at 19:18
  • @NathanOliver: Thanks this answers my question, specifically [this](https://stackoverflow.com/a/3660859/2689696) – tejas Jul 09 '21 at 19:18

0 Answers0