Cannot call @system funciton (stdout)
Simen Kjærås
simen.kjaras at gmail.com
Sun Aug 16 10:07:02 UTC 2020
On Saturday, 15 August 2020 at 23:59:36 UTC, Joel wrote:
> ../../JMiscLib/source/jmisc/base.d(176,2): Error: @safe
> function jmisc.base.upDateStatus!string.upDateStatus cannot
> call @system function
> std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal
> /Library/D/dmd/src/phobos/std/stdio.d(4837,20):
> std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal is
> declared here
>
> I got around it by avoiding 'stdout'.
First, what's wrong with using writeln and friends instead of
directly mucking about with stdout? :p
stdout is __gshared, so it's available on any thread at any time.
That's not @safe, so it's @system.
If you know you're not using stdout from multiple threads, or
don't care (it might be perfectly safe even though it's possible
to misuse), you can use this code:
@property File trustedStdout() @trusted
{
return stdout;
}
That's a @trusted wrapper that you can call from @safe code. It's
not actually safe though, as multiple threads could be using
trustedStdout at the same time. In many use cases, this is
unlikely to matter, but it's wroth keeping in mind.
--
Simen
More information about the Digitalmars-d-learn
mailing list