String literals have only one instance?

Rory Mcguire rjmcguire at gm_no_ail.com
Fri Aug 20 04:47:18 PDT 2010


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 curious about the speed of comparisons for string literals. Because
I believe the string comparisons check if a string "is" another string 
first.


More information about the Digitalmars-d-learn mailing list