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