C++ Logo


Advanced search

Subject: dynamic size of a fixed array - compiles well on gcc, why?
From: Hollowone PL (hollowonepl_at_[hidden])
Date: 2020-06-15 02:11:30

Hello everybody,

I'm writing as I'm curious about one accidental discovery, due to bug that
compiles well and works well on gcc.

I declare fixed size array like I used to for years:

   int my_array[] = { 0, 1, 2, 3, 4};

then I found code that accidentally allocates size of such array with a
variable that is defined during runtime

   int some_size = value_retrieved_from_somewhere_else;
   int my_array[some_size];
   my_array[3] = 123;

and this code compiles and works well under gcc's c++ even though some_size
is not constexpr.

Obvious bug in the compiler or some feature I'm not aware of?


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups