ldc executable crashes with this code

forkit forkit at gmail.com
Fri Feb 4 11:05:34 UTC 2022


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 that?"
>
> would be nice if programmers (C or D) learnt that a typecast 
> means "shut up compiler I know what I do". You explicitly 
> instructed the compiler to not complain.
>
> Remove the typecast and the compiler will bring an error.
>
> That's the reason why typecasts are to be avoided as much as 
> possible.It is often a code smell.

In C, I would have no such expectation.

The cast will occur whether I typed it in or not. My problem was, 
that I forgot the .dup

For the compiler to allow me to cast from immutable to mutable 
(without the .dup), makes about as much sense as the compiler 
allowing this:

int i;
i = "Hello";



More information about the Digitalmars-d-learn mailing list