Severin Teona - SAOC Milestone 3 Updates 2 & 3 - Druntime for Microcontrollers
IGotD-
nise at nise.com
Fri Dec 11 14:31:22 UTC 2020
On Friday, 11 December 2020 at 12:51:53 UTC, Severin Teona wrote:
> On Friday, 11 December 2020 at 10:27:29 UTC, IGotD- wrote:
>
>> private extern(C) _reent *__getreent();
>>
>> FILE* __stdin()() { return cast(FILE*)(__getreent()._stdin); }
>> FILE* __stdout()() { return cast(FILE*)(__getreent()._stdout);
>> }
>> FILE* __stderr()() { return cast(FILE*)(__getreent()._stderr);
>> }
>> ///
>> alias __stdin stdin;
>> ///
>> alias __stdout stdout;
>> ///
>> alias __stderr stderr;
>>
>> Is this how you solved stdin/out/err?
>
> Not exactly. I used a struct __sFile_fake for each one of
> stdin/out/err, like in newlib/libc/include/sys/reent.h.
>
> I did this after I compiled a simple C application with the -E
> flag (only preprocessing) and I saw that stdin/out/err were
> translated to _impure_ptr->_stdin/out/err. I searched for these
> symbols in newlib and I found them in reent.h.
>
> I don't know how accurate and right is it, but it seems to link
> the application ok.
That would work too I guess. The thing is that the reent
structure is initialized every time for every thread with
stdin/out/err with globals so it should be the same for each
thread too if you have dynamic reent enabled. When you compile
without dynamic reent structure __getreent() will simply pass
_impure_ptr which in turn points to a global reent.
More information about the Digitalmars-d
mailing list