On Saturday, 5 February 2022 at 03:02:37 UTC, forkit wrote:
On Friday, 4 February 2022 at 15:58:19 UTC, Stanislav Blinov
wrote:
..
...
As others have already stated, casting immutability away is
something that has to be supported, e.g. to interface with
const-agnostic APIs. `@safe` requires
On Friday, 4 February 2022 at 15:58:19 UTC, Stanislav Blinov
wrote:
..
...
As others have already stated, casting immutability away is
something that has to be supported, e.g. to interface with
const-agnostic APIs. `@safe` requires such casts to be more
verbose, with good reason.
I concede
On Fri, Feb 04, 2022 at 03:58:19PM +, Stanislav Blinov via
Digitalmars-d-learn wrote:
[...]
> As others have already stated, casting immutability away is something
> that has to be supported, e.g. to interface with const-agnostic APIs.
> `@safe` requires such casts to be more verbose, with
On Friday, 4 February 2022 at 11:26:42 UTC, forkit wrote:
If I had wrote the code below, then I should not expect
anything, whatsoever, from the compiler.
() @trustMe_I_am_a_complete_idiot { char[] palindrome =
cast(char[])"able was I ere I saw elba"; } ();
This is almost exactly what you
On Friday, 4 February 2022 at 10:09:22 UTC, Patrick Schluter
wrote:
On Thursday, 3 February 2022 at 02:01:34 UTC, forkit wrote:
On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote:
would be nice if the compiler told me something though :-(
i.e. "hey, dude, you really wanna to
On Friday, 4 February 2022 at 10:09:22 UTC, Patrick Schluter
wrote:
On Thursday, 3 February 2022 at 02:01:34 UTC, forkit wrote:
On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote:
would be nice if the compiler told me something though :-(
i.e. "hey, dude, you really wanna to
On Thursday, 3 February 2022 at 02:01:34 UTC, forkit wrote:
On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote:
would be nice if the compiler told me something though :-(
i.e. "hey, dude, you really wanna to that?"
would be nice if programmers (C or D) learnt that a typecast
On 2/2/22 10:07 PM, Tejas wrote:
On Wednesday, 2 February 2022 at 23:21:52 UTC, forkit wrote:
Any reason why compiling this with ldc would cause the exe to crash?
Compiling with DMD (using either declaration of palindrome works just
fine though)
//
module test;
import std;
void
On 2/3/22 12:53 AM, forkit wrote:
But @safe or not, nothing good can come from casting an immutable string
to a mutable string, and the compiler really should know that ;-)
If you have a function that accepts mutable data, but you know for that
call it won't mutate the data (or maybe it's
I know we are talking about something else but just to make sure, there
is no need for the cast, copy, or .reverse:
const palindrome = "able was I ere I saw elba";
writeln(palindrome);
writeln(palindrome.retro);
Ali
On Thursday, 3 February 2022 at 03:25:39 UTC, H. S. Teoh wrote:
On Thu, Feb 03, 2022 at 02:01:34AM +, forkit via
Digitalmars-d-learn wrote: [...]
would be nice if the compiler told me something though :-(
i.e. "hey, dude, you really wanna to that?"
Mark your function @safe, and the
On Thu, Feb 03, 2022 at 02:01:34AM +, forkit via Digitalmars-d-learn wrote:
[...]
> would be nice if the compiler told me something though :-(
>
> i.e. "hey, dude, you really wanna to that?"
Mark your function @safe, and the compiler will stop you from unsafe
casts of this nature. That's
On Wednesday, 2 February 2022 at 23:21:52 UTC, forkit wrote:
Any reason why compiling this with ldc would cause the exe to
crash?
Compiling with DMD (using either declaration of palindrome
works just fine though)
//
module test;
import std;
void main()
{
char[] palindrome =
On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote:
would be nice if the compiler told me something though :-(
i.e. "hey, dude, you really wanna to that?"
On Thu, Feb 03, 2022 at 01:39:33AM +, forkit via Digitalmars-d-learn wrote:
> On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote:
> > On Wed, Feb 02, 2022 at 11:21:52PM +, forkit via Digitalmars-d-learn
> > wrote: [...]
> > > char[] palindrome = cast(char[])"able was I ere
On Thursday, 3 February 2022 at 01:51:34 UTC, Basile B. wrote:
On Thursday, 3 February 2022 at 01:39:33 UTC, forkit wrote:
On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh
wrote:
[...]
that explains ldc perhaps (although i don't really get it.
It's cast to mutable and being
On Thursday, 3 February 2022 at 01:39:33 UTC, forkit wrote:
oops! forgot the .dup
char[] palindrome = cast(char[])"able was I ere I saw elba".dup;
;-)
On Thursday, 3 February 2022 at 01:39:33 UTC, forkit wrote:
On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote:
[...]
that explains ldc perhaps (although i don't really get it. It's
cast to mutable and being assigned to mutable.
in any case... ldc doesn't like it, but dmd is
On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote:
On Wed, Feb 02, 2022 at 11:21:52PM +, forkit via
Digitalmars-d-learn wrote: [...]
char[] palindrome = cast(char[])"able was I ere I saw
elba";
String literals are immutable by default. Casting immutable to
mutable
is
On Wed, Feb 02, 2022 at 11:21:52PM +, forkit via Digitalmars-d-learn wrote:
[...]
> char[] palindrome = cast(char[])"able was I ere I saw elba";
String literals are immutable by default. Casting immutable to mutable
is UB (Undefined Behaviour).
[...]
> writeln(palindrome.reverse);
Any reason why compiling this with ldc would cause the exe to
crash?
Compiling with DMD (using either declaration of palindrome works
just fine though)
//
module test;
import std;
void main()
{
char[] palindrome = cast(char[])"able was I ere I saw elba";
//char[] palindrome
21 matches
Mail list logo