String literals have only one instance?

2010-08-19 Thread Rory Mcguire
Are all string literals that have the same value initialized to the same address? void main() { string same() { return "This"; } assert("This" is same()); assert("This" is "This"); } Can this be relied upon?

Re: String literals have only one instance?

2010-08-19 Thread Jonathan Davis
On 8/19/10, Rory Mcguire wrote: > Are all string literals that have the same value initialized to the same > address? > > void main() { > string same() { > return "This"; > } > assert("This" is same()); > assert("This" is "This"); > } > > > Can this be relied

Re: String literals have only one instance?

2010-08-19 Thread bearophile
Rory Mcguire: > Are all string literals that have the same value initialized to the same > address? > ... > Can this be relied upon? Probably a conforming D implementation is free to not give the same address to those. Bye, bearophile

Re: String literals have only one instance?

2010-08-19 Thread Stewart Gordon
Jonathan Davis wrote: You can always check with the is operator though. If it reports true, then the two strings have the same instance. If it reports false, then they don't. I can't see how testing each string literal to see if it's the same instance as another can work. The OP's point is:

Re: String literals have only one instance?

2010-08-19 Thread Johannes Pfau
On 19.08.2010 09:53, Rory Mcguire wrote: > Are all string literals that have the same value initialized to the same > address? > > void main() { > string same() { > return "This"; > } > assert("This" is same()); > assert("This" is "This"); > } > > > Can thi

Re: String literals have only one instance?

2010-08-19 Thread Simen kjaeraas
Rory Mcguire wrote: Are all string literals that have the same value initialized to the same address? void main() { string same() { return "This"; } assert("This" is same()); assert("This" is "This"); } Can this be relied upon? No. The same s

Re: String literals have only one instance?

2010-08-19 Thread Sean Kelly
Rory Mcguire Wrote: > Are all string literals that have the same value initialized to the same > address? > > void main() { > string same() { > return "This"; > } > assert("This" is same()); > assert("This" is "This"); > } > > > Can this be relied upon? T

Re: String literals have only one instance?

2010-08-20 Thread Rory Mcguire
Rory Mcguire wrote: > Are all string literals that have the same value initialized to the same > address? > > void main() { > string same() { > return "This"; > } > assert("This" is same()); > assert("This" is "This"); > } > > > Can this be relied upon? Interesting thanks guys. Was just curi