why static array can be reassigned with new allocation?

Ali Çehreli acehreli at yahoo.com
Fri Oct 14 20:19:20 UTC 2022


On 10/14/22 11:57, mw wrote:

 >      arr = new int[5];

That syntax is confusing. Although it looks like a static array, it's a 
dynamic array of length 5.

 > Why this code can be compiled and causing runtime error? it should be
 > caught at compile time!

The compiler does not perform detailed analysis of all code. Since that 
5 could be a runtime expression, the compiler does not check it at 
compile time.

Ali



More information about the Digitalmars-d mailing list