This is the mail archive of the gcc@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: switch question in recog.c


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.


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