Manually allocating a File

Nicholas Wilson iamthewilsonator at hotmail.com
Wed Feb 21 02:59:21 UTC 2018


On Tuesday, 20 February 2018 at 15:32:45 UTC, Chris M. wrote:
> Thanks for the info, that clears things up. Like I said, it was 
> more experimentation rather than me planning to actually use 
> it. Works now with the following modifications.
>
> import std.stdio;
> import core.stdc.stdlib;
> import std.conv;
>
> void main()
> {
>     auto f = cast(File*) malloc(File.sizeof);
>     emplace!File(f, "test.txt", "r");
>     f.readln.write;
>     free(f);
> }
>
>>>     (*f).readln.writeln;
>>
>> That * is unnecessary btw, in D you can
>>
>> f.readln
>>
>> and it will see it is a pointer to struct and dereference it 
>> for you.
>
> That's what I had originally, but I put the * in to see if it 
> would help with the original issue and never removed it

FYI, File is a reference counted FILE* so theres not really any 
point of heap allocating it.


More information about the Digitalmars-d-learn mailing list