[Issue 10344] Exiting _Dmain should flush all FILE*s and return nonzero on failure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 12 12:15:12 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10344



--- Comment #2 from Andrei Alexandrescu <andrei at erdani.com> 2013-06-12 12:15:11 PDT ---
(In reply to comment #1)
> On one hand, I disagree that stdout failing to flush on program exit should
> trump whatever main returns.  The application simply may not care.

I just tested this:

import std.stdio;
int main()
{
    return fflush(null);
}

Fortunately it never fails, which is quite awesome because it means it'll fail
only if the application attempted to produce output but was unable to.

If the upstream app has no interest in whether the invoked app produced proper
output, they can ignore the exit code.

> On the other hand, if stdout is invalid, and any output is done, writeln could
> fail itself at any time.  If this is not expected, the effect is the same.
> 
> This can be opt-out also:
> 
> int main()
> {
>    ....
>    try { fflush(NULL); } catch {}
>    return 0;
> }
> 
> So I'm OK with this.

fflush doesn't throw.

> I still think it's worth checking on first write whether the file descriptor is
> valid (this only needs to be done for File instances opened with an existing
> FILE * or file descriptor).  The advantage here is that the error occurs at
> first use, not at some time later (possibly at program end!).  If the user is
> simply using an invalid file descriptor, I'd rather see the exception at use,
> not on program exit.

That's nice, but I'm not sure whether we should do it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list