[comp.lang.c] A perverse switch statement.

flee@shire.cs.psu.edu (Felix Lee) (10/13/89)

Something sparked by comp.std.c's "declarations in switches"
discussion.  Duff's device and Obfuscated C: all perverse.

main()
{
	int i, j = 1;
	for (i = 0; i <= 6; ++i)
		switch (i)
		top:
		case 6:	{
			int k = 3;
		case 0:	for (; ++k % 3; ++j) {
		case 1:		printf(" j = %d,", j);
		case 2:		printf(" k = %d\n", k);
			}
		case 3: printf("i = %d\n", i); break;
		case 4: printf("i = %d\n", i);
		case 5:	goto top;
		}
}
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!flee

davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (10/14/89)

In the example below it makes the code even more obscure to add a
conditional break within the for in the switch in the for. See below
after "case 1"

In article <FLEE.89Oct13095510@shire.cs.psu.edu>, flee@shire.cs.psu.edu (Felix Lee) writes:

|  main()
|  {
|  	int i, j = 1;
|  	for (i = 0; i <= 6; ++i)
|  		switch (i)
|  		top:
|  		case 6:	{
|  			int k = 3;
|  		case 0:	for (; ++k % 3; ++j) {
|  		case 1:		printf(" j = %d,", j);
				if (i == 4) break;
|  		case 2:		printf(" k = %d\n", k);
|  			}
|  		case 3: printf("i = %d\n", i); break;
|  		case 4: printf("i = %d\n", i);
|  		case 5:	goto top;
|  		}
|  }

  Sorry for the big quote, but the code is hard enough to read complete,
and I doubt that anyone other than the author would follow the
discussion without seeing the source.
-- 
bill davidsen	(davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon