Ignore:
Timestamp:
Feb 12, 2018, 1:33:42 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ee2938a
Parents:
43c6dc82
Message:

Added half page on choose and other switch enhancements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Paper.tex

    r43c6dc82 r48786bc8  
    10441044The implicit targets of the current @continue@ and @break@, \ie the closest enclosing loop or @switch@, change as certain constructs are added or removed.
    10451045
    1046 \TODO{choose and fallthrough here as well?}
    1047 
     1046\subsection{\texorpdfstring{Enhanced \LstKeywordStyle{switch} Statement}{Enhanced switch Statement}}
     1047
     1048\CFA also fixes a number of ergonomic defecits in the @switch@ statements of standard C.
     1049C can specify a number of equivalent cases by using the default ``fall-through'' semantics of @case@ clauses, \eg @case 1: case 2: case 3:@ -- this syntax is cluttered, however, so \CFA includes a more concise list syntax, @case 1, 2, 3:@.
     1050For contiguous ranges, \CFA provides an even more concise range syntax as well, @case 1~3:@; lists of ranges are also allowed in case selectors.
     1051
     1052Forgotten @break@ statements at the end of @switch@ cases are a persistent sort of programmer error in C, and the @break@ statements themselves introduce visual clutter and an un-C-like keyword-based block delimiter.
     1053\CFA addresses this error by introducing a @choose@ statement, which works identically to a @switch@ except that its default end-of-case behaviour is to break rather than to fall through for all non-empty cases.
     1054Since empty cases like @case 7:@ in @case 7: case 11:@ still have fall-through semantics and explicit @break@ is still allowed at the end of a @choose@ case, many idiomatic uses of @switch@ in standard C can be converted to @choose@ statements by simply changing the keyword.
     1055Where fall-through is desired for a non-empty case, it can be specified with the new @fallthrough@ statement, making @choose@ equivalently powerful to @switch@, but more concise in the common case where most non-empty cases end with a @break@ statement, as in the example below:
     1056
     1057\begin{cfa}
     1058choose( i ) {
     1059        case 2:
     1060                printf("even ");
     1061                fallthrough;
     1062        case 3: case 5: case 7:
     1063                printf("small prime\n");
     1064        case 4,6,8,9:
     1065                printf("small composite\n");
     1066        case 13~19:
     1067                printf("teen\n");
     1068        default:
     1069                printf("something else\n");
     1070}
     1071\end{cfa}
    10481072
    10491073\subsection{\texorpdfstring{\LstKeywordStyle{with} Clause / Statement}{with Clause / Statement}}
Note: See TracChangeset for help on using the changeset viewer.