Using array slices with C-style fread() from file
uncorroded via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 21 12:20:29 PDT 2017
On Wednesday, 21 June 2017 at 19:11:44 UTC, Ali Çehreli wrote:
> On 06/21/2017 12:06 PM, uncorroded wrote:
>
> > Is
> > there any way of making the function with @safe as well? I
> get the
> > errors "cannot call @system function
> 'core.stdc.stdio.fread,fopen,fclose'.
>
> @trusted is exactly for that. It can be called from @safe code:
>
> @trusted @nogc ubyte[n] rand_bytes(uint n)() {
> // ...
> }
>
> @safe auto foo() {
> return rand_bytes!3();
> }
>
> Ali
Thanks! So @trusted is me guaranteeing to the compiler that this
function is safe? Is there any way of auditing this code through
valgrind, etc. Also, thanks a lot for your book on D. It has been
an invaluable resource in getting me started.
More information about the Digitalmars-d-learn
mailing list