Why is switch (ptr) illegal (or how to pointers differ from scalers)?

Mark A Terribile mat at mole-end.UUCP
Sun Dec 18 04:20:15 AEST 1988


 | NOTE do, re, mi;
 | 
 | and the pointer:
 | NOTE *scale;
 | 
 | Why can I not do:
 | 
 | 	switch (scale) {
 | 
 | 	case &do:
 | 		do_something (scale);
 | 		break;

The switch() requires *compile-time* constants, rather than link-time constants
so that the compiler can determine which of several methods (table look-up,
range-checked indexing, hashed back-checked lookup, if/then ...) it should use.

Could it be changed to always do a linear search table lookup (worst case) on
a link-time expression?  Probably.  Would it encourage bad style?  Perhaps.
Should it be done?  I don't know.
-- 

(This man's opinions are his own.)
>From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list