This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
- From: Tim Hollebeek <tim at hollebeek dot com>
- To: Kevin Lawton <kevinlawton2001 at yahoo dot com>
- Cc: Zack Weinberg <zack at codesourcery dot com>, Michael Matz <matz at suse dot de>, Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>, gcc at gcc dot gnu dot org
- Date: Tue, 15 Oct 2002 19:17:24 -0700
- Subject: Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
- References: <20021016004929.GO15067@codesourcery.com> <20021016013810.22926.qmail@web80304.mail.yahoo.com>
- Reply-to: tim at hollebeek dot com
On Tue, Oct 15, 2002 at 06:38:10PM -0700, Kevin Lawton wrote:
>
> --- Zack Weinberg <zack@codesourcery.com> wrote:
>
> > Sure. The question is how _soon_ you will be screwed to the point
> > that the program crashes. Ideally this happens as soon after the
> > actual data corruption event as possible.
>
[snip]
>
> If we wanted to stop people from shooting theirselves
> in the feet, we wouldn't allow them to use C. At
> any rate, sometimes it's even possible to prove the
> case targets are populated:
>
> switch (a & 0x3) {
then ask for the compiler to understand and DTRT with this syntax,
instead of some funky attribute.
Sure, recognizing "switch ((expr) & (integral constant 2^n-1))" only
works for tables that are powers of two, but I suspect that would
already go quite a ways towards what many people need.
BTW, the "if you don't like the extension, don't use it" argument
doesn't wash. Extensions have a non-trivial maintenance burden that
has to be supported by the gcc development team, and that's a far more
valuable resource than a few cycles in a few people's code.