Defining constant values in struct

Alex Parrill via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 16 17:47:57 PDT 2015


On Tuesday, 16 June 2015 at 21:17:37 UTC, tcak wrote:
> As far as I known, when I define a string with enum and it is 
> used at different parts of code, that string is repeated again 
> and again in executable file instead of passing a pointer to 
> string. So, using enum with string doesn't seem like a good 
> idea.

String literals are merged by the compiler, much like in C and 
Java.

import std.stdio;
enum mystring = "hello world!";

void main() {
	string str1 = mystring;
	string str2 = mystring;
	
	writeln(str1.ptr == str2.ptr); // prints true
}



More information about the Digitalmars-d-learn mailing list