Re: stdout.flush
On 5/25/16 2:09 PM, Charles Hixson via Digitalmars-d-learn wrote: Using: dmd --version DMD64 D Compiler v2.071.0 on debian Linux, and importing: importstd.stdio; the line: flush(); causes: nt.d(29): Error: undefined identifier 'flush', did you mean function 'fflush'? This appears solved by doing stdout.flush; (compiles, but I'm still writing the code) but as write, writef, etc. don't require explicitly mentioning stdout, I think that the documentation for flush should mention that the file must be specified. Currently it seems to imply that all files will be flushed. write, writef, etc. are all forwarding functions to stdout.write, stdout.writef, etc. It's not that it doesn't require mentioning stdout, it's that you have a shortcut defined. Just like C has printf, and fprintf, we have both. But because this isn't C, we don't need to change the name :) flush as a standalone function is not supported at this time. I doubt it will be. -Steve
stdout.flush
Using: dmd --version DMD64 D Compiler v2.071.0 on debian Linux, and importing: importstd.stdio; the line: flush(); causes: nt.d(29): Error: undefined identifier 'flush', did you mean function 'fflush'? This appears solved by doing stdout.flush; (compiles, but I'm still writing the code) but as write, writef, etc. don't require explicitly mentioning stdout, I think that the documentation for flush should mention that the file must be specified. Currently it seems to imply that all files will be flushed.
Re: Is stdout.flush() unsafe?
On 12/29/15 4:57 AM, tsbockman wrote: Trying to compile this: void main() @safe { import std.stdio; stdout.flush(); } Fails with this message: Error: safe function 'main' cannot access __gshared data 'stdout' Is this necessary? If so, what are the synchronization requirements for access to `stdout`? Hm... what is needed is an accessor for stdout: void main() @safe { import std.stdio; auto safe_stdout() @trusted { return stdout; } safe_stdout.flush(); } The issue is the storage class __gshared is banned from accessing in safe code (because it is subject to races). So you have to claim to the compiler "I know this is generally not safe, but I have encapsulated it in a way to make it safe". Likely, this is what we should do for all the standard streams, not being able to access streams in safe code seems a steep restriction. -Steve
Is stdout.flush() unsafe?
Trying to compile this: void main() @safe { import std.stdio; stdout.flush(); } Fails with this message: Error: safe function 'main' cannot access __gshared data 'stdout' Is this necessary? If so, what are the synchronization requirements for access to `stdout`?