The D Programming Language: cases

Richard Harter g-rh at cca.CCA.COM
Thu Mar 3 15:12:05 AEST 1988


In article <2403 at umd5.umd.edu> chris at trantor.umd.edu (Chris Torek) writes:
>-In article <24996 at cca.CCA.COM> g-rh at cca.CCA.COM (Richard Harter) writes:
>-}As a side point, I like the suggestion that someone made that there be
>-}a fallthrough statement rather than automatic fallthrough.

>While this would work, if we assume D has aggregate constructors,
>there is a handsomer way:

>	switch (e) {
>	case [1, 2, 3, 5, 7, 13, 19, 23]: ...
>	}
>	/* syntax above is only for demonstration */

Well, yes, one ought to be able to do that.  However it is isn't quite
as strong as fallthrough, where one can say

	switch (e) {
	  case foo:
	    some code;
	    fallthrough;
	  case baz:
	    some more code;
	  }


In C as it stands now you can do this -- indeed, the complaint is that
one can do this unintentionally.  If one adds aggregate constructors and
takes away automatic fallthrough, it seems to me that you weaken the
language.   No doubt there are purists that say you shouldn't do the
sort of thing given above.  I wouldn't go that far, but I would agree
that one should be able to use aggregate constructors when cases actually
share code.

-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list