another compiler bug?
Marcin Kuszczak
aarti_please_no at spam_interia.pl
Sun Jan 13 06:56:52 PST 2008
Frits van Bommel wrote:
> No, it's just initialized once. However, the struct itself isn't
> returned; a *copy* of it is returned. That copy is what's modified by
> the assignment. The second call will return a fresh copy of the original
> (with "test" remaining the string value).
>
>> This behaviour is different when we change Pattern to be class instead of
>> struct. Then it is possible to create kind of singleton pattern for every
>> type.
>
> Yes, class instances are passed by reference, so the assignment would
> change the 'static' instance (assuming you 'new' it the first time
> around, so there is one).
> The same effect should be observed if you change the function to:
> -----
> Pattern!(T)* get(T)() {
> static Pattern!(T) pattern;
> return &pattern;
> }
> -----
> for the struct version (returning a pointer to the global instance
> instead of a copy of it).
>
Thanks! Now this behaviour is clear for me.
>>
>> BTW. Where should I discuss bugs? I have another dozen of them and would
>> like to discuss some of them before posting to bugzilla. Is it better to
>> post to d.learn or d.bugs?
>
> If they are of the same kind as this one, you may want to stick to
> d.learn as it's not actually a bug :P.
> (Or at least, it's a bug in your code rather than in the compiler; the
> compiler does exactly what I'd expect it to do and what IMO it should do)
Some of them probably are bugs, and some of them are not. That's why I
prefer to discuss them before posting to bugzilla.
--
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://www.zapytajmnie.com (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
More information about the Digitalmars-d-learn
mailing list