Array literals MUST be immutable.

Michel Fortin michel.fortin at
Fri Feb 19 09:59:36 PST 2010

On 2010-02-19 11:03:30 -0500, "Steven Schveighoffer" 
<schveiguy at> said:

>> //the cast is only there to shut up the stupid dmd!
>> int[] arr = cast(int[])([0, 1, 2]);
> Yes, but a cast is a red flag.  A simple appending of brackets is not.  
> It  is well established that casts are to let you do things that in 
> most  contexts are not a good idea.  Brackets are not the same.

That's the theory. It doesn't quite work in practice because you 
sometime have to cast to convert from one type to another (float to 
int, base class to derived), or to make a literal of the type you want 
(especially with array literals). Many usages of cast are safe, many 
aren't. So seeing cast as a red flag doesn't really work, unfortunately.

Even SafeD allows cast, it just restricts it to safe usages.

Michel Fortin
michel.fortin at

More information about the Digitalmars-d mailing list