== comparison of string literals, and their usage

AltFunction1 af1af1af1 at af1.af1
Sat Apr 6 14:07:00 UTC 2019


On Friday, 5 April 2019 at 14:49:50 UTC, diniz wrote:
> Hello,
>
> Since literal strings are interned (and immutable), can I count 
> on the fact that they are compared (==) by pointer?

No. "==" performs a full array comparison and "is" is apparently 
simplified at compile time. In the compiler there's no notion of 
string literal as a special expression. It's always a StringExp. 
See https://d.godbolt.org/z/K5R6u6.

However you're right to say that literal are not duplicated.




More information about the Digitalmars-d-learn mailing list