Calendar Functions

Guido van Rossum guido at mcvax.uucp
Tue Sep 23 08:16:42 AEST 1986


Wouldn't Jim Cottrell love this:

	#define leapyear(y) !((y)&3)

	daysinmonth(m, y) {
		if (m == 2) return 28 + leapyear(y);
		return 30 + ((1&m) ^ (m>7));
	}

Seriously, I believe that the original code, which applied the same rule
here showed a discrepancy between its seemingly clear coding style
(explaining every simple statement with a comment) and the 'trick' in
the algorithm (invert the parity of the month for months > 7).

In my eyes the solution which uses a table is the cleanest.



More information about the Comp.lang.c mailing list