This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Optimize ((c>=1)&&(c<=127)) into ((signed char)c>0)


Roger Sayle <roger@eyesopen.com> writes:
> + void
> + test (unsigned char c, int ok)
> + {
> +   if ((c>=1) && (c<=127))
> +     {
> +       if (!ok) abort ();
> +     }
> +   else
> +     if (ok) abort ();
> + }
> +
> + int
> + main ()
> + {
> +   test (  0, 0);
> +   test (  1, 1);
> +   test ( 64, 1);
> +   test (127, 1);
> +   test (128, 0);
> +   test (192, 0);
> +   test (255, 0);
> +   return 0;
> + }

Perhaps consider CHAR_BIT in <limits.h>?

-- 
Lars Brinkhoff          http://lars.nocrew.org/     Linux, GCC, PDP-10,
Brinkhoff Consulting    http://www.brinkhoff.se/    HTTP programming


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]