Why Does The C-Compiler Do This?

utzoo!decvax!duke!harpo!seismo!dmy utzoo!decvax!duke!harpo!seismo!dmy
Tue Jan 11 14:42:22 AEST 1983


I'm puzzled by an action of the (4.1absd) c-compiler.
Consider the fragments:

	int a,b;   a = 2  * 3  * b * 4;
	float a,b; a = 2. * 3. * b * 4.;

In the first case, it (intelligently) does one multiply of 24 by b.  In the
second case, it (poorly) does two multiplies, of 6. by b and the result by 4.
Why isn't the generated code exactly parallel?  Certainly the language allows
it, there's no question of overflow, and the expressions should be parsed and
code-generated in the same way.  Any comments?

--dmy--



More information about the Comp.lang.c mailing list