Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 29, 2018 Make string literals immutable in Windows | ||||
---|---|---|---|---|
| ||||
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. |
November 30, 2018 Re: Make string literals immutable in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Pennebaker | 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.
|
November 30, 2018 Re: Make string literals immutable in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Pennebaker | 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.
|
December 01, 2018 Re: Make string literals immutable in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | 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 |
December 01, 2018 Re: Make string literals immutable in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Pennebaker | 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.
|
Copyright © 1999-2021 by the D Language Foundation