Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mailrus!cornell!uw-beaver!uw-june!pardo From: pardo@june.cs.washington.edu (David Keppel) Newsgroups: comp.lang.c Subject: Must the "switch" quantity be an integer? Summary: Barfs on switch((foo_t*)i) { ... } Message-ID: <6137@june.cs.washington.edu> Date: 19 Oct 88 19:23:25 GMT Reply-To: pardo@cs.washington.edu (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 51 [ appologies if this was just discussed ] I want to declare a bunch of "magic" pointers, e.g., as is done in /usr/include/signal.h: #define BUFPTR ((os_t *)1) #define SPTR ((os_t *)2) : And do things like: foo[0] = BUFPTR; foo[1] = (os_t *) malloc (sizeof(os_t)); : then: switch (foo[i]) { case BUFPTR: /* handle magic case #1 */ break; case SPTR: /* handle magic case #2 */ break; case ... : : default: normal (foo[i]); } When I compile this with pcc, everything is happy. When I compile this with gcc and turn on all of the flags for dpANS (-ansi, -pedantic), the compiler refuses to accept the code since "switch quantity is not an integer". This *is* certainly true, but isn't what I expected. I wasn't aware that dpANS required the switch quantity to be an integer (or, presumably things such as chars that can be converted to integers implicitly). Two questions: (a) What are the rules? (b) Can I do this portably without using a mass of if (foo[i]==BUFPTR) { ... } else if (foo[i]==SPTR)... code? (Or, "*can* I do this portably?") ;-D on ( Compilo ad adsurd-bum ) Pardo -- pardo@cs.washington.edu {rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo