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 (eliminationof the bounds check)
- From: Michael Matz <matz at suse dot de>
- To: Tim Hollebeek <tim at hollebeek dot com>
- Cc: Kevin Lawton <kevinlawton2001 at yahoo dot com>,Zack Weinberg <zack at codesourcery dot com>,Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>, <gcc at gcc dot gnu dot org>
- Date: Wed, 16 Oct 2002 10:48:12 +0200 (CEST)
- Subject: Re: Request of new __attribute__ for switch statements (eliminationof the bounds check)
Hi,
On Tue, 15 Oct 2002, Tim Hollebeek wrote:
> > 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.
Although remember that we have two cases in this thread. Things like
fully populated "switch (a & A_CONSTANT)" or "switch (a_char)", which
clearly should be optimized by the compiler itself without syntantic help.
And that "switch (an_enum)" thing, also "fully populated" in the sense
that all enumeration values are mentioned. But due to the definition of
C/C++ this isn't fully populated, because an enum variable is equivalent
to a var of it's base int type, and can hold values without a name. For
that we would need a syntactic mean to differentiate between standard
enums (named int constants) and real ones (a set).
Ciao,
Michael.