gets(3) nonsense

Guy Harris guy at auspex.UUCP
Fri Nov 18 03:26:48 AEST 1988


>Allright. I tried `clarification through exaggeration', and obviously I
>failed.

Yes, because it didn't clarify - the two cases were different.

>No no! "Of course somebody put it in so you can avoid the nasty run-time
>overhead!" Indeed, one could doubt if the writer of gets() really had that
>very point in mind, but it sure comes in handy right now.

Oh, really?  I doubt that as well.  The extra time spent making sure you
don't overflow the buffer is likely to be washed away by the time spent
reading the data in the first place.

>So use fgets()! You're right insofar that public utilities should use fgets()
>(or something equivalent), but there ARE cases in which you can be absolutely
>sure how stdin is formatted

But in many cases where you think you can be sure, you may be in for a
rude surprise.  Consider program A which writes a file and program B
which reads it.  Of COURSE you wrote both programs, so of COURSE they
agree on conventions, right?  Well, unless you're sure 1) you didn't
screw up and 2) you'll be maintaining both programs, you may find, to
your surprise, that someday they may *not* agree....

>(or cases in which one simply says: if stdin is badly formatted, bad
>luck - YOU f*ck around, YOU get the core dump!).

Unfortunately, I don't trust people to do this only on programs that
only they will use.  I also don't trust people, including myself, to
remember that this program responds rather poorly to input lines that
are too long....



More information about the Comp.lang.c mailing list