Casting away immutability

jqb via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 4 03:44:23 PDT 2015


On Thursday, 3 September 2015 at 13:28:54 UTC, Sergei Degtiarev 
wrote:
[...]
> Agree, however, memory obtained with mmap(..., PROT_READ, ..); 
> is essentially read-only and any attempt to write to it will 
> cause immediate crash with segmentation violation. It would be 
> very desirable in this case to return something that could be 
> cast to immutable(type)[] but not type[].
> This is what I tried to find out. Thank you for the help.

It can still change by writing (in the same or another process) 
to the file via another file descriptor. Of course the results 
are non-deterministic in that case, so it doesn't much matter 
whether the compiler assumes the data to be immutable or not.


More information about the Digitalmars-d-learn mailing list