home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18477 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.5 KB  |  36 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  3. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  4. Subject: Re: find the number difference of dates
  5. Message-ID: <1992Dec16.182904.19703@klaava.Helsinki.FI>
  6. Organization: University of Helsinki
  7. References: <1992Dec11.103710.1@sysjj.mdcbbs.com>
  8. Date: Wed, 16 Dec 1992 18:29:04 GMT
  9. Lines: 25
  10.  
  11. lembark@sysjj.mdcbbs.com writes:
  12. >(time_t)-1 works since time_t is normally an unsigned quantity;
  13. >(time_t)~0 does the same basic thing (32 bits of 0xFFF... will do the
  14. >same thing).
  15.  
  16. (time_t)-1 works because it is defined so.  The author of the C
  17. library has to choose time_t so that the cast will work.  I do not
  18. know whether time_t is normally an unsigned quantity (it isn't on the
  19. machines I have access to, both of them running different versions of
  20. Unix), but assuming anything about time_t's type is not a good idea.
  21. Even the assumption that -1 and ~0 have the same representation is
  22. invalid (it only works on systems with two's complement representation
  23. for negative numbers).
  24.  
  25. time_t is an abstraction, and you shouldn't assume anything about what
  26. it looks like on the inside.  Use the documented interface (the
  27. functions in time.h, e.g. time, gmtime, localtime, difftime, mktime)
  28. to manipulate things.
  29.  
  30. The same rules apply for other abstract types defined by the library.
  31. For example, don't go mucking with the internals of a FILE object.
  32.  
  33. --
  34. Lars.Wirzenius@helsinki.fi  (finger wirzeniu@klaava.helsinki.fi)
  35.    MS-DOS, you can't live with it, you can live without it.
  36.