[net.unix-wizards] C compiler bug?

mw.uci@Rand-Relay@sri-unix (10/25/82)

From:      Mark Wadsworth <mw.uci@Rand-Relay>
Date:      21 Oct 82 0:19:48-PST (Thu)
main()
      {
	printf("%D\n",60L*60L*24L*((1970L-1900L)*365L + 1970L/4L - 1900L/4L));
      }

      This program, surprisingly enough, prints out 0.  The expression evaluates
      to 0.  Is anyone aware of any particular reason for this absurdity?

      John Woods

The value is too big for 32 bits. On my system (Berkeley Unix, VAX) it prints
-2085978496

obrien@RAND-UNIX@sri-unix (10/27/82)

Date: Sunday, 24 Oct 1982 23:25-PDT
main()
      {
	printf("%D\n",60L*60L*24L*((1970L-1900L)*365L + 1970L/4L - 1900L/4L));
      }

	Yep.  It's too big.  "bc" comes through with its
arbitrary precision and says that this is = 2208988800, while
2^31 = 2147483648 (yes that's the same number of digits so in
some sense it's "just barely" too big).