How do you document breakless cases

Ray Butterworth rbutterworth at watmath.waterloo.edu
Wed Jul 6 02:53:50 AEST 1988


In article <739 at vsi.UUCP>, sullivan at vsi.UUCP (Michael T Sullivan) writes:
> In article <16607 at tut.cis.ohio-state.edu>, lvc at tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes:
>
> >     1 /* fallthrough */
> >         if the last statement before a case isn't one of
> >             return
> >             exit
> >             abort
> >             etc.
>
> return is different that exit and abort.  Lint knows that return isn't coming
> back, wheras exit and abort are just functions.  I ran into this the other
> day where my switch had all cases and default that returned and one that exited.
> Lint complained about the one that exited with a "function has return and
> return(e)" type of message.  I put a /*NOTREACHED*/ after the exit and lint
> was much happier.

Our version of lint has both a /*FALLTHROUGH*/ directive for the switch
statement, and a /*GOTO*/ directive for external declarations.
e.g. <stdlib.h> should contain:  extern /*GOTO*/ exit();
then any program that includes <stdlib.h> will lint correctly
and never need /*NOTREACHED*/.  The following lints cleanly:

    extern /*GOTO*/ exit();
    extern /*GOTO*/ abort();

    main(argc)
    {
        switch (argc) {
            case -3:
            case -2:
            case -1:
                abort();
            case 0:
                return 0;
            case 1:
                ++argc;
                /*FALLTHROUGH*/
            case 2:
                ++argc;
                exit(argc);
            default:
                return 42;
        }
    }


If anyone else implements these, it would be nice if they used the
same keywords instead of inventing yet another name.



More information about the Comp.lang.c mailing list