www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Make string literals immutable in Windows

reply Andrew Pennebaker <andrew.pennebaker gmail.com> writes:
I was surprised to read from the FreeBSD documentation that D 
string literals are actually writeable in Windows:

https://dlang.org/dmd-freebsd.html

Can we fix that? I think C literals were already immutable, 
though I'm not sure about the particulars of the Visual Studio 
C/C++ semantics.
Nov 29 2018
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 29 November 2018 at 23:56:27 UTC, Andrew Pennebaker 
wrote:
 I was surprised to read from the FreeBSD documentation that D 
 string literals are actually writeable in Windows:
I don't think that is true anymore, but even if it is, you would have to cast away the language-level immutable to get to it, so it is undefined behavior anyway.
Nov 29 2018
prev sibling next sibling parent reply bauss <jj_1337 live.dk> writes:
On Thursday, 29 November 2018 at 23:56:27 UTC, Andrew Pennebaker 
wrote:
 I was surprised to read from the FreeBSD documentation that D 
 string literals are actually writeable in Windows:

 https://dlang.org/dmd-freebsd.html

 Can we fix that? I think C literals were already immutable, 
 though I'm not sure about the particulars of the Visual Studio 
 C/C++ semantics.
They're not writable in the sense you think so it doesn't really matter. Strings are still constructed as immutable(char)[] on Windows. It's the same across all platforms. I guess the difference is that you can cast immutable away and that's UB and thus it doesn't really matter.
Nov 30 2018
parent Jacob Carlborg <doob me.com> writes:
On 2018-11-30 10:24, bauss wrote:

 They're not writable in the sense you think so it doesn't really matter.
 
 Strings are still constructed as immutable(char)[] on Windows. It's the 
 same across all platforms.
 
 I guess the difference is that you can cast immutable away and that's UB 
 and thus it doesn't really matter.
I know in the D1 days when a string literal was of the type "char[]". Then string literals were placed in a read only section in the binary on Posix, trying to modify a string literal caused a segfault (or similar). On Windows it worked fine to modify a string literal. -- /Jacob Carlborg
Dec 01 2018
prev sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Thursday, 29 November 2018 at 23:56:27 UTC, Andrew Pennebaker 
wrote:
 I was surprised to read from the FreeBSD documentation that D 
 string literals are actually writeable in Windows:

 https://dlang.org/dmd-freebsd.html

 Can we fix that? I think C literals were already immutable, 
 though I'm not sure about the particulars of the Visual Studio 
 C/C++ semantics.
Please provide an example of valid D program that does this. Seriously though, it would be a nice thing to have.
Dec 01 2018