Trouble at EOF

Chris Dollin kers at hplb.hpl.hp.com
Mon Jun 17 19:07:21 AEST 1991


Ed Nilges says (about fgets and the optional newline):

   be the Edge of the World, but this seems a tad bogus, especially
   if one is writing a lexical analyser where such issues are
   important.  

If I was writing a lexical analyser in C, I certainly would not first read in
the entire line, not even with fgets; I'd read in characters as required. (How
big a biffer should I allocate for fgets? What do I do on line overflow? These
are questions I wish to unask.)

Is the overhead of reading characters with fgetc really so large? (I suppose if
the lexis is suitable bizarre, you may need lots of putback, and being able to
just backbump the line index is easy. I find it a crying shame that stdio
doesn't mandate arbitrary putback. Still, it's not as bad as Lisp - at least C
has an excuse.)
--

Regards, Chris ``GC's should take less than 0.1 second'' Dollin.



More information about the Comp.lang.c mailing list