[Issue 4378] Array Literals as Default Field Initializers Shared Across Instances.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 24 05:32:49 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4378


nfxjfg at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg at gmail.com


--- Comment #4 from nfxjfg at gmail.com 2010-06-24 05:32:46 PDT ---
How is this supposed to work "correctly"? Hidden allocation of an array on the
heap every time a struct of that type is "constructed"? Disallow initializing
non-immutable, non-static array members?

This is not a bug, it's just D _works_. If you assign an array to a global
variable, of course it's shared by everyone. Dynamic arrays are reference
types. The "variable" being a struct initializer doesn't change this.

I think this really should be marked as INVALID.

(I'm sure it's somewhat confusing for programmers coming from C++ or Java.
Especially in Java, the array would be reconstructed every time the constructor
is called. Stuff like this _never_ happens in D: structs are always initialized
by what boils down to a memcpy.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list