Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83 (MC840302); site boring.UUCP
Path: utzoo!watmath!clyde!cbosgd!ihnp4!houxm!mhuxr!ulysses!allegra!mit-eddie!godot!harvard!seismo!mcvax!boring!guido
From: guido@boring.UUCP
Newsgroups: net.lang.c
Subject: type of long % int
Message-ID: <6265@boring.UUCP>
Date: Thu, 27-Dec-84 18:10:35 EST
Article-I.D.: boring.6265
Posted: Thu Dec 27 18:10:35 1984
Date-Received: Sat, 29-Dec-84 02:52:57 EST
Reply-To: guido@boring.UUCP (Guido van Rossum)
Organization: "Stamp Out BASIC" Committee, CWI, Amsterdam
Lines: 30
Apparently-To: rnews@mcvax.LOCAL

Since the result of a%b can never exceed abs(b) in absolute value, it would
be reasonable that a%b gets the type of b, not of a.  This is more reasonable
in an example like this:

	fiddle(diskaddr) long diskaddr; {
		int offset= diskaddr%BUFSIZ;
		...
	}

where which lint currently complaints about a long to int assignment.

I can see only one disadvantage (besides it being a strange exception to
an otherwise simple rule: "the type  of the result of any arithmetic
operation is the type of the 'larger' operand"): it breaks programs that
say, for instance,

	/* Assume int a, b; */
	foobar((long)a%b); /* foobar requires a 'long' argument */

instead of

	foobar((long)(a%b));

which is better anyway because it casts at the right moment; but the former
is currently also correct (passes lint).

Any comments?  Ansi committee?

	Guido van Rossum, "Stamp Out BASIC" Committee, CWI, Amsterdam
	guido@boring.UUCP