Changeset 9d7a19f
- Timestamp:
- Jun 23, 2026, 9:09:53 PM (107 minutes ago)
- Branches:
- master
- Parents:
- 366f5cd
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r366f5cd r9d7a19f 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon May 4 12:09:44202614 %% Update Count : 74 4013 %% Last Modified On : Tue Jun 23 20:56:16 2026 14 %% Update Count : 7474 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 3661 3661 allowable calls are: 3662 3662 \begin{cquote} 3663 \begin{tabular}{@{}l l@{}}3663 \begin{tabular}{@{}l@{\hspace{80pt}}l@{}} 3664 3664 \textbf{positional arguments} & \textbf{empty arguments} \\ 3665 3665 \begin{cfa} … … 3687 3687 Here the missing arguments are inserted from the default values in the parameter list. 3688 3688 The compiler rewrites missing default values into explicit positional arguments. 3689 While it is possible to put default parameters before positional, it is always necessary to use the ©?© for ommision. 3690 \begin{cfa} 3691 void f( int x ®= 10®, int y ); 3692 f( 4, 4 ); 3693 f( ?, 4 ) 3694 \end{cfa} 3695 3696 The parameter default-expression can be evaluated at compile (C) or runtime time (\CC) in the declaration context. 3697 \begin{cfa} 3698 enum { y = 10 }; 3699 void f( int x ®= y / 2® ); §\C{// C static declaration-site expression-computation}§ 3700 f(); §\C{// rewrite \(\Rightarrow\) f( 5 )}§ 3701 int y = 200, z = 100; 3702 void g( int x ®= y / z® ); §\C{// \CFA/\,\CC dynamic declaration-site expression-computation}§ 3703 g(); §\C{// rewrite \(\Rightarrow\) g( 2 )}§ 3704 \end{cfa} 3705 In \CFA, it is possible to have the default-expression evaluated at the call site using a trait. 3706 \begin{cfa} 3707 forall( | { int y; int z; } ) §\C{// define local trait for h}§ 3708 void h( int x = y / z ); §\C{// \CFA dynamic call-site expression-computation}§ 3709 void foo() { 3710 h(); §\C{// rewrite using globals \(\Rightarrow\) h( 2 )}§ 3711 int y = 50, z = 5; 3712 h(); §\C{// rewrite using locals \(\Rightarrow\) h( 10 )}§ 3713 y = 25; 3714 h(); §\C{// rewrite using locals \(\Rightarrow\) h( 5 )}§ 3715 } 3716 \end{cfa} 3717 Routine ©h©'s trait requires variables ©y© and ©z© in the call environment, which are used to compute the default initialization. 3718 3689 3719 The advantages of default values are: 3690 3720 \begin{itemize} … … 3808 3838 3809 3839 \CFA named and default arguments are backwards compatible with C. 3810 \Index*[C++]{\CC{}} only supports default parameters;3840 \Index*[C++]{\CC{}} only supports left to right default parameters; 3811 3841 \Index*{Ada} supports both named and default parameters. 3812 3842
Note:
See TracChangeset
for help on using the changeset viewer.