What does 'scope' mean for non-class types?

div0 div0 at users.sourceforge.net
Sun May 30 17:15:51 PDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon wrote:
> div0 wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Lars T. Kyllingstad wrote:
>>> In D2, what is the effect (if any) of 'scope' in the following
>>> situations?
>>>
>>>   scope int a;
>>
>> Nothing
> 
> http://www.digitalmars.com/d/2.0/attribute.html#scope
> "This means that the destructor for an object is automatically called
> when the reference to it goes out of scope."
> So there are two ways to interpret this:
> 
> - primitive types don't have destructors, so it shouldn't compile
> 
> - the destructor of a primitive type is nop, 

Meh. I don't really care either which way, though perhaps for the sake
of writing template code it should continue to be allowed as a nop.

> so the reason it has no effect at the moment is
> http://d.puremagic.com/issues/show_bug.cgi?id=2483

No, that bug is completely different.
None of Lars example code involved assigning to a scope var after it's
declaration. We've discussed this before; allowing assignment to a scope
variable raise questions about which object should actually be deleted.

> 
>>>   struct B { ... }
>>>   scope B b;
>>
>> Nothing, B's destructor will be called even without scope.
>>
>>>   scope int[] c;
>>
>> c gets deleted when the scope ends. this applies to classes as well.
> <snip>
> 
> What gets deleted - the array or the individual objects?
> 
> Stewart.

Just the array. There maybe references to those objects elsewhere.
Though if the compiler can do escape analysis and prove all the objects
are dead, then they should be deleted at end of scope as well.

- --
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFMAv+3T9LetA9XoXwRAv5LAJ9mNl15pW1sK13c5atEGttv9PSHGgCgpoAB
k6t+UtPQRZgknLm4ozD/tgY=
=ZNfg
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list