Is it OK that gcc optimizes away overflow check?

Andrew Haley aph@redhat.com
Tue Jul 26 17:31:00 GMT 2011


On 07/26/2011 11:35 AM, Andrew Haley wrote:

> Consider
> 
>   for (i = 0; i < limit; i++)
>     f(i * 2);
> 
> which can be rewritten to
> 
>   tmp = limit * 2;
>   for (i = 0; i < tmp; i++)
>     f(i);

duh.

  int tmp = limit * 2;
  for (i = 0; i < tmp; i += 2)
    f(i);

Andrew.



More information about the Gcc-help mailing list