Getting a reference to an immutable string

ag0aep6g anonymous at example.com
Sat Feb 10 22:36:41 UTC 2018


On 02/10/2018 11:26 PM, David Zhang wrote:
> I've got an immutable string declared in module scope, and I attempted 
> to get a pointer to its characters through both &str[0] and str.ptr. 
> However, it appears to me that the string is behaving like a manifest 
> constant, in that the pointer is null.
> 
> The language reference indicates that it has a location in memory and 
> thus has a pointer.
> 
> So, my question is thus: Is this a bug in DMD, or is this just something 
> I missed?

The pointer should not be null, even when `str` is a manifest constant. 
But without code it's impossible to say if you're hitting a compiler bug 
or if you're doing something wrong.


More information about the Digitalmars-d-learn mailing list