struct comparison

Tim McDaniel mcdaniel at uicsrd.csrd.uiuc.edu
Sat Jul 29 15:39:45 AEST 1989


In article <2288 at auspex.auspex.com> guy at auspex.auspex.com (Guy Harris)
writes:
>OK, what if I want to see if one file offset is larger than, or smaller
>than, another?
...
>Perhaps add and subtract aren't as common as other operators, but I'd
>still be a bit annoyed if I couldn't add and subtract file offsets;
>unlike structure comparison, I've used addition of file offsets on a
>number of occasions.

The BSD 4.3 man page for fseek(3S) and ftell(3S) says:

     _Ftell_ returns the current value of the offset relative to
     the beginning of the file associated with the named _stream_.
     It is measured in bytes on UNIX; on some other systems it is
     a magic cookie, and the only foolproof way to obtain an
     _offset_ for _fseek_.

K&R 2, 1st edition, p. 248, says (for fseek):

     For a binary file, the position is set to _offset_ characters
     from _origin_, which may be SEEK_SET (beginning), SEEK_CUR
     (current postion), or SEEK_END (end of file).  For a text stream,
     _offset_ must be zero, or a value returned by _ftell_ (in which
     case _origin_ must be SEEK_SET).

Thus, in pANS C, a *text* stream offset may indeed be a "magic
cookie", for which comparison and arithmetic is undefined.  Binary
mode requires an actual character number.  (Personally, I see no point
in having the distinction; I'd like to see all _offset_s be magic
cookies.  It's too late, now that X3J11 has acted.)

--
"Let me control a planet's oxygen supply, and I don't care who makes
the laws." - GREAT CTHUHLU'S STARRY WISDOM BAND (via Roger Leroux)
 __
   \         Tim, the Bizarre and Oddly-Dressed Enchanter
    \               mcdaniel at uicsrd.csrd.uiuc.edu
    /\       mcdaniel%uicsrd@{uxc.cso.uiuc.edu,uiuc.csnet}
  _/  \_     {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel



More information about the Comp.std.c mailing list