How to call a C function from D that takes a FILE * as an argument?
WebFreak001
d.forum at webfreak.org
Wed Jul 4 08:40:09 UTC 2018
On Wednesday, 4 July 2018 at 02:54:47 UTC, Joe wrote:
> On Wednesday, 4 July 2018 at 02:16:00 UTC, Seb wrote:
>> Hmm, calling e.g. fprintf with stdout should just work:
>>
>> ---
>> void main()
>> {
>> import core.stdc.stdio;
>> fprintf(stdout, "Hello %s", "world".ptr);
>> }
>> ---
>>
>> Could you maybe provide your whole code?
>
> This short test program shows the error:
>
> ---
> import std.stdio;
>
>
> void main()
> {
> extern (C) void list(FILE *fd);
> list(stdout);
> }
> ---
>
> Now I fixed this by changing the import to core.stdc.stdio. I
> guess the problem is if you import std.stdio (which brings in
> the other one), there are two slightly incompatible stdout's
> and the D takes precedence.
`stdout.getFP` (stdout is of the D std.stdio.File struct type and
with getFP you get the underlying FILE*)
More information about the Digitalmars-d-learn
mailing list