malloc(s)[0..s] vs cast(T)malloc(s)

Jack jckj33 at
Wed Oct 14 20:15:39 UTC 2020

What's the difference between:

>import core.stdc.stdlib : malloc;
>auto x = malloc(s)[0..s];
>auto x = cast(T)malloc(s);

I have been using the last but I saw in some code examples, like 
this[1] the first being used. What's the difference? in the first 
one bounds checking is performed, giving an error right away, 
right? whereas the cast would just turn the null into the class 
reference and manual check need to be done later. Is that the 


More information about the Digitalmars-d-learn mailing list