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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 13 07:25:46 PDT 2013


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



--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> 2013-06-13 07:25:43 PDT ---
(In reply to comment #2)
> (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.

Right, this is definitely ideal.  One should not throw an error because stdout
is broken if you never use stdout.

But that was not my point.  My point is that what you write in stdout may not
be critical.  It may be a side effect, like let's say a log or informational
message.  In that case, you don't care if it fails, you are more interested in
what the program decides the error code should be.

For instance, imagine a program that takes as input some database commands, and
prints out how many rows were updated, but returns 1 if the database commands
failed, and 0 if it succeeded.  I don't care as an upstream script function
whether "5 rows updated" successfully printed, I only care if the database was
successfully updated.

> > This can be opt-out also:
> > 
> > int main()
> > {
> >    ....
> >    try { fflush(NULL); } catch {}
> >    return 0;
> > }
> > 
> > So I'm OK with this.
> 
> fflush doesn't throw.

oops, I meant stdout.flush(); stderr.flush();

> > 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.

It's simply an optimization.  There is little overhead required (a simple bool
indicating whether it should check the fd on first write).

-- 
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