Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!munnari.oz.au!metro!toshiba!csdc_3!colin From: colin@toshiba.tic.oz (Colin Sutton) Newsgroups: comp.object Subject: Re: Documenting OO Systems Keywords: operators Message-ID: Date: 5 Apr 91 00:58:05 GMT Article-I.D.: csdc_3.colin.670813085 References: <299@orbit.gtephx.UUCP> <1991Mar25.145441.1@happy.colorado.edu> <20106@alice.att.com> <3481@engadm3.csd.mot.com> <1991Mar26.191259.14470@i88.isc.com> <4693@osc.COM> horvath@motcid.UUCP (Bob Horvath) writes: >pallas@eng.sun.com (Joseph Pallas) writes: >-I can't believe I'm about to waste my time on this, but here goes: >-int j (int year, int month, int day) { >-int month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; >-if (month<1 || month>12) return 0; >-int leap = !(year%4) && year&400; >-if (day<1 || day>(month_days[month-1] + (month==2 && year))) return 0; >-int dayofmonth = 0; >-for (int i=0; i-return dayofmonth + day + (month>2 && year); >-} >-I've left the name of the function cryptic, but the rest is the result >-of a simple global substitution. It becomes immediately apparent not >-only what the function is supposed to do, but that it contains at >-least one error (surely you meant to check (month==2 && leap)). I can't read C either, but I think I see another bug (or a specification error). Years that are a multiple of 100 are not leap years, except multiples of 400. Most software that doesn't care about centuries will work just fine until 2100! What's C doing in this newsgroup anyway? ;-) --- Colin Sutton Project Manager, Computer Systems Development Centre Toshiba International Corporation Pty. Ltd. Tel. Sydney 428 2077 Australian Company Number 001 555 068 email: colin@toshiba.tic.oz.au