This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: switch question in recog.c
- From: Michael Matz <matz at suse dot de>
- To: Andrew MacLeod <amacleod at redhat dot com>
- Cc: Daniel Jacobowitz <drow at mvista dot com>,gcc mailing list <gcc at gcc dot gnu dot org>
- Date: Wed, 8 Oct 2003 00:27:23 +0200 (CEST)
- Subject: 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.