public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Matz <matz@suse.de>
To: Tim Hollebeek <tim@hollebeek.com>
Cc: Kevin Lawton <kevinlawton2001@yahoo.com>,
	Zack Weinberg <zack@codesourcery.com>,
	Jamie Lokier <egcs@tantalophile.demon.co.uk>, <gcc@gcc.gnu.org>
Subject: Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
Date: Wed, 16 Oct 2002 14:23:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.33.0210162210460.20702-100000@wotan.suse.de> (raw)
In-Reply-To: <20021016131437.A25171@hollebeek.com>

Hi,

On Wed, 16 Oct 2002, Tim Hollebeek wrote:

> > And that "switch (an_enum)" thing, also "fully populated" in the sense
> > that all enumeration values are mentioned.
>
> Cases like that that are performance critical, not a factor of two,
> and cannot be expanded to a factor of two?  I don't buy it.

Why should they have to be expanded to ^2?  That's also syntactic sugar
(because semantically not needed), and doesn't express exactly what one
wants (which is a real set of values), besides cluttering up the switch
statement (consider an "enum {BASE=0, OTHER=0x7fff};" which strictly would
need to check two values only, whereas with your work-around would need to
check 0x8000 of them).  The extension of strict enums would not have
application _only_ in optimizations but also in type checking.

> Remember, we already have -Wswitch, and default: abort(), which are

"default: abort()" is an even more hidden hint for optimization than an
explicit attribute on an enum to be strict.  That also can be used for
optimization hint, but isn't quite like not having a default case at all
(after all if you write "default: abort();" that's only a hint to the
compiler that this case is extremely unlikely, whereas with an strict enum
you ensure to the compiler, that non-enumerated values are _impossible_).

> adequate for all but the most performance intensive cases.

Sure, but I don't see, how such a meta type (strict enums) is useless, as
language mean _and_ as optimization hint.  C IMHO actually lacks a real
set type (it's already usefull to support one-element subset variables,
instead of fully featured subset vars like Pascal), and this extension, if
well thought out (I don't think there are too many issues) could actually
find its way to ISO C.

That having said, this strict enum proposal is just hot air unless someone
begins to implement it.  I don't know enough about the frontends to do
this currently.


Ciao,
Michael.

  reply	other threads:[~2002-10-16 20:27 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-11 13:20 Kevin Lawton
2002-10-12  4:18 ` Ralph Loader
2002-10-14  8:31 ` Richard Zidlicky
2002-10-14 10:09   ` Dale Johannesen
2002-10-14 21:11 ` Jamie Lokier
2002-10-14 22:01   ` Zack Weinberg
2002-10-15  8:12     ` Michael Matz
2002-10-15 19:15       ` Zack Weinberg
2002-10-15 19:18         ` Dale Johannesen
2002-10-16 14:07           ` Richard Henderson
2002-10-15 21:16         ` Kevin Lawton
2002-10-15 23:40           ` Tim Hollebeek
2002-10-16  3:40             ` Michael Matz
2002-10-16 13:38               ` Tim Hollebeek
2002-10-16 14:23                 ` Michael Matz [this message]
2002-10-16 13:27             ` Hartmut Schirmer
2002-10-16  3:25         ` Joseph S. Myers
2002-10-16  7:57           ` Fergus Henderson
2002-10-16 11:19           ` Daniel Jacobowitz
2002-10-15  7:54   ` Michael Matz
2002-10-15 13:29     ` Jamie Lokier
2002-10-15 14:06       ` Kevin Lawton
2002-10-15 15:32         ` Jamie Lokier
2002-10-15 14:28       ` Michael Matz
2002-10-15 15:19         ` Jamie Lokier
2002-10-11 13:22 Robert Dewar
2002-10-11 15:12 ` Kevin Lawton
2002-10-12 10:43   ` Alexandre Oliva
2002-10-15  6:43 Mattias Engdegård
2002-10-15 22:40 Robert Dewar
2002-10-15 23:57 ` Zack Weinberg
2002-10-16  9:19 Robert Dewar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33.0210162210460.20702-100000@wotan.suse.de \
    --to=matz@suse.de \
    --cc=egcs@tantalophile.demon.co.uk \
    --cc=gcc@gcc.gnu.org \
    --cc=kevinlawton2001@yahoo.com \
    --cc=tim@hollebeek.com \
    --cc=zack@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).