An amusing piece of code

LINNDR%VUENGVAX.BITNET at wiscvm.ARPA LINNDR%VUENGVAX.BITNET at wiscvm.ARPA
Mon Apr 7 05:52:24 AEST 1986


In posting<1370 at ism780c.UUCP>, Tim Smith asks about a switch with common
code for some cases. I have seen two solutions.

1) put the common code in a subroutine
        switch(thing) {
        case A: A-code; break;
        case B: B-code; BCD-common-code(); break;
        case C: C-code; BCD-common-code(); break;
        case D: D-code; BCD-common-code(); break;
        case E: E-code; break;
        }

2) use the much abused goto statment
        switch(thing) {

        case A: A-code; break;

        case B: B-code; goto BCD_common;

        case C: C-code; goto BCD_common;

        case D: D-code;

    BCD_common: BCD-common-code;
                break;

        case E: E-code; break;
        }


Hope one of these helps you.

David Linn
----------------------------------------------------------
BITNET:         LINNDR at VUEngVAX.BITNET or PEARL at VANDVMS1.BITNET
MAILNET:        LINN_D_R    \
                David_R_Linn >@VANDERBILT.MAILNET
                David_Linn  /
CSNET:          drl at vanderbilt.csnet
SnailMail:      P.O. 3241-B Vanderbilt
                Nashville, TN   37235



More information about the Comp.lang.c mailing list