Re: ldc executable crashes with this code

2022-02-07 Thread bauss via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-04 Thread forkit via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-04 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-04 Thread Stanislav Blinov via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-04 Thread forkit via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-04 Thread forkit via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-04 Thread Patrick Schluter via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-03 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-03 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-03 Thread Ali Çehreli via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread Tejas via Digitalmars-d-learn
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 =

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
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?"

Re: ldc executable crashes with this code

2022-02-02 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread Basile B. via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
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; ;-)

Re: ldc executable crashes with this code

2022-02-02 Thread Basile B. via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
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

Re: ldc executable crashes with this code

2022-02-02 Thread H. S. Teoh via Digitalmars-d-learn
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);

ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
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