optimizer question

Zoltan.2.Varga@nokia.com Zoltan.2.Varga@nokia.com
Fri Sep 20 12:15:00 GMT 2002


				Hi,

   When confronted with the following code:

void main()
{
	int x = 2;
	int y;

	y = rand();
	y = y / x;
	printf("%d.\n", y);
}

Why does gcc generate a division instead of a shift ? Is this a shortcoming of the optimizer or some feature of C I don't 
understand ? When I replace the 'x' in the division with '2', a shift is generated. I'm using gcc-3.2 -O3 on x86 linux.

				thanks

					Zoltan



More information about the Gcc-help mailing list