Changeset 538cc35


Ignore:
Timestamp:
Jan 30, 2024, 9:45:08 PM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
3da5885
Parents:
2989d6f
Message:

small updated to uC++toCFA document

Location:
doc/uC++toCFA
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/uC++toCFA/Makefile

    r2989d6f r538cc35  
    88BibTeX = BIBINPUTS=../bibliography: && export BIBINPUTS && bibtex
    99
    10 MAKEFLAGS = --no-print-directory --silent #
     10MAKEFLAGS = --no-print-directory # --silent
    1111VPATH = ${Build} ${Figures}
    1212
  • doc/uC++toCFA/uC++toCFA.tex

    r2989d6f r538cc35  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Oct 15 23:09:58 2023
    14 %% Update Count     : 5926
     13%% Last Modified On : Thu Jan 11 14:46:14 2024
     14%% Update Count     : 5942
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    428428\begin{uC++}
    429429struct S {
    430         int i = 0;
     430        int i = 0;  // cheat, implicit default constructor
    431431        int setter( int j ) { int t = i; i = j; return t; }
    432432        int getter() { return i; }
     
    434434
    435435S s;
    436 @s.@setter( 3 );  // object-oriented call
     436@s.@setter( 3 );  // object-oriented calls
    437437int k = @s.@getter();
    438438\end{uC++}
     
    442442        int i;
    443443};
    444 void ?{}( S & s ) { s.i = 0; }
     444void ?{}( S & s ) { s.i = 0; } // explicit default constructor
    445445int setter( @S & s,@ int j ) @with(s)@ { int t = i; i = j; return t; }
    446446int getter( @S & s@ ) @with(s)@ { return i; }
    447447S s;
    448 setter( @s,@ 3 );  // normal routine call
     448setter( @s,@ 3 );  // normal routine calls
    449449int k = getter( @s@ );
    450450\end{cfa}
     
    458458\begin{tabular}{l|l}
    459459\begin{uC++}
     460
    460461struct S {
    461462        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};
    465466int 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
    476476struct S {
    477477        int i;
    478478};
    479 void ?{}( S & s, int i ) { s.i = i; sout | s.i; }
    480 S s[10] @$\color{red}@$= {}@;
     479void ?{}( S & s, int i ) { s.i = i; sout | "ctor" | s.i; }
     480void ^?{}( S & s ) { sout | "dtor" | s.i; }
    481481int 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;
    488486}
    489487\end{cfa}
Note: See TracChangeset for help on using the changeset viewer.