Changeset bc999b7
- Timestamp:
- Dec 8, 2024, 9:09:02 AM (10 days ago)
- Branches:
- master
- Children:
- fbb5bdd
- Parents:
- 9f7285e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/fangren_yu_MMath/intro.tex
r9f7285e rbc999b7 122 122 In addition, several operations are defined in terms of values @0@ and @1@, \eg: 123 123 \begin{cfa} 124 if ( x) x++ $\C{// if (x != 0) x += 1;}$124 if ( x ) ++x $\C{// if ( x != 0 ) x += 1;}$ 125 125 \end{cfa} 126 126 Every @if@ and iteration statement in C compares the condition with @0@, and every increment and decrement operator is semantically equivalent to adding or subtracting the value @1@ and storing the result. … … 129 129 \begin{cfa} 130 130 struct S { int i, j; }; 131 void ?{}( S & s, zero_t ) { s.[i,j] = 0; } 131 void ?{}( S & s, zero_t ) { s.[i,j] = 0; } $\C{// constructors}$ 132 132 void ?{}( S & s, one_t ) { s.[i,j] = 1; } 133 int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } 134 S ? +=?( S & s, one_t ) { s.i++; s.j++; return s; }135 S ? -=?( S & s, one_t ) { s.i--; s.j--; return s; }136 S ? =?( S & dst, one_t ) { return dst.[i,j] = 1; }137 void foo() { 138 139 s = @1@;140 if ( @s@ ) @s++@;141 } 133 S ?=?( S & dst, zero_t ) { dst.[i,j] = 0; return dst; } $\C{// assignment}$ 134 S ?=?( S & dst, one_t ) { dst.[i,j] = 1; return dst; } 135 S ?+=?( S & s, one_t ) { s.[i,j] += 1; return s; } $\C{// increment/decrement}$ 136 S ?-=?( S & s, one_t ) { s.[i,j] -= 1; return s; } 137 int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } $\C{// comparison}$ 138 S s = @0@; 139 s = @0@; 140 s = @1@; 141 if ( @s@ ) @++s@; $\C{// unary ++/-\,- come from +=/-=}$ 142 142 \end{cfa} 143 143 Hence, type @S@ is first-class with respect to the basic types, working with all existing implicit C mechanisms.
Note: See TracChangeset
for help on using the changeset viewer.