case stmt != jumptable of goto labels !!!!!!!!!

Ozan Yigit oz at yetti.UUCP
Fri Feb 21 01:57:25 AEST 1986


Why is it, when someone asks whether or not jumptables with
goto labels are allowed in C, there is the overwhelming
response "use a case statement" ????

It is not the same, except in one isolated circumstance, where
the user-created jumptable is completely static.

Furthermore:

[1] You are never guaranteed to get a jumptable out of a
case statement. If you get it with compiler X, you may not
get with compiler Y. [the reason may be a buggy implementation
or whatever, but would be unnoticable,  since it does not
effect the correctness of the generated code]

[2] The structure of the case jumptable may be different from
compiler to compiler. [Vaxen Cc may generate a jump table of
relative offsets to feed to case[wl] instruction, whereas others
may generate a table of direct addresses]

[3] The jumptable is hidden, thus cannot be manipulated. (unless,
of course, you are practicing black magic :-)

I can see some weird application where a jumptable of goto labels
is used, and program dynamically alters the control flow by
swapping labels on the jump table, or by adding new ones in. Surely
this would be most unreadable, and difficult to debug, and something
I would classify as "pornographic programming", but than, It is proven
nicely in "obfuscated C" contests that one can do a lot worst.

Please hold your flame, in case you are ready to lit. I am not suggesting
that C should have the capability, [Although it is certainly debatable]
nor am I suggesting that a jumptable with goto labels is necessary, 
where jumptables with function entries could easily be created. 
All I am arguing against is the unthinking suggestion that 
case == jumptable of labels.

Oz
-- 

Usenet: [decvax|allegra|linus|ihnp4]!utzoo!yetti!oz
Bitnet: oz@[yusol|yuyetti]
	FREE SOFTWARE FOUNDATION vs. EMPIRE. Watch for
	things to come..



More information about the Comp.lang.c mailing list