switch question in recog.c

Michael Matz matz@suse.de
Tue Oct 7 22:27:00 GMT 2003


Hi,

On 7 Oct 2003, Andrew MacLeod wrote:

> Huh. I would have failed that question miserably after using the
> language for 20 years.

Then you never used a variant of the holy, mighty device from Tom Duff ;-)

Constructed useless example (i.e. not the usual memcpy() unrolling):

------------------
extern void abort ();
int f(int i)
{
  switch (i & 1) {
    while (1) {
      if (i > 32) {
        abort ();
        case 0: return 1;
      } else {
        abort ();
        case 1: return 2;
      }
      default: break;
    }
  }
}

int main()
{
  if (f (42) != 1)
    abort ();
  return 0;
}
------------------

"case x" is a normal label (with the exception that it's scoped to the
enclosing case statement) introducing a labeled statement, hence it can be
placed everywhere as long as it's inside a switch.  Sometimes I love C ;-)


Ciao,
Michael.



More information about the Gcc mailing list