Is this a desing rationale? (static array object member)

downs default_357-line at yahoo.de
Sat Sep 29 16:11:47 PDT 2007


> Brian Hsu wrote:
> The compiler will create 3 array instance (Test.z, fun1.x, fun2.x)
since they appear 3 time, and they will be at last translate to memory
address at compile time. So in facts the code is looks like:
>
> class Test
> {
>     int [] z = 0xFFFFF; // memory address of the array create by array
literal
> }
>
> That's why different instance of class Test will have object member z
point to same array instance. Is this correctly?

Eh, I kinda assumed this was the normal behavior, but the other replies
are indicating that this is merely a compiler artifact. So it would
appear that the compiler _currently_ relates each literal to one area of
memory, but that might change.

The only safe way is probably to do what the others said - always dup
literals before use. Sorry I can't help you further.

 --downs ._.



More information about the Digitalmars-d mailing list