Changeset 538cc35 for doc/uC++toCFA
- Timestamp:
- Jan 30, 2024, 9:45:08 PM (9 months ago)
- Branches:
- master
- Children:
- 3da5885
- Parents:
- 2989d6f
- Location:
- doc/uC++toCFA
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/uC++toCFA/Makefile
r2989d6f r538cc35 8 8 BibTeX = BIBINPUTS=../bibliography: && export BIBINPUTS && bibtex 9 9 10 MAKEFLAGS = --no-print-directory --silent #10 MAKEFLAGS = --no-print-directory # --silent 11 11 VPATH = ${Build} ${Figures} 12 12 -
doc/uC++toCFA/uC++toCFA.tex
r2989d6f r538cc35 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sun Oct 15 23:09:58 202314 %% Update Count : 59 2613 %% Last Modified On : Thu Jan 11 14:46:14 2024 14 %% Update Count : 5942 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 428 428 \begin{uC++} 429 429 struct S { 430 int i = 0; 430 int i = 0; // cheat, implicit default constructor 431 431 int setter( int j ) { int t = i; i = j; return t; } 432 432 int getter() { return i; } … … 434 434 435 435 S s; 436 @s.@setter( 3 ); // object-oriented call 436 @s.@setter( 3 ); // object-oriented calls 437 437 int k = @s.@getter(); 438 438 \end{uC++} … … 442 442 int i; 443 443 }; 444 void ?{}( S & s ) { s.i = 0; } 444 void ?{}( S & s ) { s.i = 0; } // explicit default constructor 445 445 int setter( @S & s,@ int j ) @with(s)@ { int t = i; i = j; return t; } 446 446 int getter( @S & s@ ) @with(s)@ { return i; } 447 447 S s; 448 setter( @s,@ 3 ); // normal routine call 448 setter( @s,@ 3 ); // normal routine calls 449 449 int k = getter( @s@ ); 450 450 \end{cfa} … … 458 458 \begin{tabular}{l|l} 459 459 \begin{uC++} 460 460 461 struct S { 461 462 int i; 462 S( int i ) { S::i = i; cout << S::i << endl; }463 }; 464 @uNoCtor<S>@ s[10];463 S( int i ) { S::i = i; cout << "ctor " << S::i << endl; } 464 ~S() { S::i = i; cout << "dtor " << S::i << endl; } 465 }; 465 466 int main() { 466 for ( int i = 0; i < 10; i += 1 ) { 467 s[i].ctor( i ); 468 } 469 for ( int i = 0; i < 10; i += 1 ) { 470 cout << s[i]@->@i << endl; 471 } 472 } 473 \end{uC++} 474 & 475 \begin{cfa} 467 enum { N = 5 }; 468 @uNoCtor<S>@ s[N]; // no constructor calls 469 for ( int i = 0; i < N; i += 1 ) @s[i].ctor( i )@; 470 for ( int i = 0; i < N; i += 1 ) cout << s[i]@->@i << endl; 471 } 472 \end{uC++} 473 & 474 \begin{cfa} 475 #include @<raii.hfa>@ // uninit 476 476 struct S { 477 477 int i; 478 478 }; 479 void ?{}( S & s, int i ) { s.i = i; sout | s.i; }480 S s[10] @$\color{red}@$= {}@; 479 void ?{}( S & s, int i ) { s.i = i; sout | "ctor" | s.i; } 480 void ^?{}( S & s ) { sout | "dtor" | s.i; } 481 481 int main() { 482 for ( i; 10 ) { 483 ?{}( s[i], i ); // call constructor 484 } 485 for ( i; 10 ) { 486 sout | s[i]@.@i; // dot not arrow 487 } 482 enum { N = 5 }; 483 @uninit(S)@ s[N]; // no constructor calls 484 for ( i; N ) @s[i]{ i }@; 485 for ( i; N ) sout | s[i]@.@i; 488 486 } 489 487 \end{cfa}
Note: See TracChangeset
for help on using the changeset viewer.