Must the "switch" quantity be an integer?

Karl Heuer karl at haddock.ima.isc.com
Thu Oct 20 13:56:55 AEST 1988


In article <8706 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <6137 at june.cs.washington.edu> pardo at cs.washington.edu (David Keppel) writes:
>>    #define	BUFPTR		((os_t *)1)
>
>This is quite non-portable.  ANSI C requires that there be some integral
>type to which a pointer can be cast then uncast without loss of information,
>but the integral type isn't necessarily int, and random integer values need
>not be castable to pointers.

True, except that "without loss of information" should be "and still compare
equal to the original".  You can lose information (e.g. runtime array bound
checking), but nothing that the program would be depending on.

>If you really have to have os_t*-shaped magic numbers, consider ...
>	#define BUFPTR (&dummy_buf)
>	case (ptrint_t)BUFPTR:

C'mon Doug, you know better than that.  That isn't a valid integral constant
expression.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list