Changeset bb20aa6
- Timestamp:
- Jul 26, 2024, 7:01:17 AM (8 months ago)
- Branches:
- master
- Children:
- fcbb532
- Parents:
- fd4df379
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified doc/user/user.tex ¶
rfd4df379 rbb20aa6 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Thu Jul 25 16:53:43202414 %% Update Count : 69 4513 %% Last Modified On : Fri Jul 26 06:56:11 2024 14 %% Update Count : 6955 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 3326 3326 \subsection{Default} 3327 3327 3328 A default parameter provides the ability to associatea default value with a parameter so it can be optionally specified in the argument list.3328 A default parameter associates a default value with a parameter so it can be optionally specified in the argument list. 3329 3329 For example, given the routine prototype: 3330 3330 \begin{cfa} … … 3337 3337 \textbf{positional arguments} & \textbf{empty arguments} \\ 3338 3338 \begin{cfa} 3339 f(); 3340 f( 4 ); 3341 f( 4, 4 ); 3342 f( 4, 4, 4 ); 3339 f(); §\C[0.75in]{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}§ 3340 f( 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§ 3341 f( 4, 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§ 3342 f( 4, 4, 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 4, 4 )}\CRT§ 3343 3343 3344 3344 … … 3347 3347 & 3348 3348 \begin{cfa} 3349 f( ?, 4, 4 );§\C[1.0in]{// rewrite \(\Rightarrow\) f( 1, 4, 4 )}§3350 f( 4, ?, 4 );§\C{// rewrite \(\Rightarrow\) f( 4, 2, 4 )}§3351 f( 4, 4, ? );§\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§3352 f( 4, ?, ? );§\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§3353 f( ?, 4, ? );§\C{// rewrite \(\Rightarrow\) f( 1, 4, 3 )}§3354 f( ?, ?, 4 );§\C{// rewrite \(\Rightarrow\) f( 1, 2, 4 )}§3355 f( ?, ?, ? );§\C{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}\CRT§3349 f( ®?®, 4, 4 ); §\C[1.0in]{// rewrite \(\Rightarrow\) f( 1, 4, 4 )}§ 3350 f( 4, ®?®, 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 2, 4 )}§ 3351 f( 4, 4, ®?® ); §\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§ 3352 f( 4, ®?®, ®?® ); §\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§ 3353 f( ®?®, 4, ®?® ); §\C{// rewrite \(\Rightarrow\) f( 1, 4, 3 )}§ 3354 f( ®?®, ®?®, 4 ); §\C{// rewrite \(\Rightarrow\) f( 1, 2, 4 )}§ 3355 f( ®?®, ®?®, ®?® ); §\C{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}\CRT§ 3356 3356 \end{cfa} 3357 3357 \end{tabular} 3358 3358 \end{cquote} 3359 where the ©?© selects the default value as the argument. 3359 3360 Here the missing arguments are inserted from the default values in the parameter list. 3360 3361 The compiler rewrites missing default values into explicit positional arguments. … … 3406 3407 the number of required overloaded routines is linear in the number of default values, which is unacceptable growth. 3407 3408 In general, overloading is used over default parameters, if the body of the routine is significantly different. 3408 Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list , via a missing argument, such as:3409 \begin{cfa} 3410 f( 1, ?, 5 ); §\C{// rewrite \(\Rightarrow\) f( 1, 2, 5 )}§3409 Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list. 3410 \begin{cfa} 3411 f( 1, ®?®, 5 ); §\C{// rewrite \(\Rightarrow\) f( 1, 2, 5 )}§ 3411 3412 \end{cfa} 3412 3413 … … 3449 3450 3450 3451 The named parameter is not part of type resolution; 3451 the type of the expression assigned to the named parameter affects type resolution.3452 only the type of the expression assigned to the named parameter affects type resolution. 3452 3453 \begin{cfa} 3453 3454 int f( int ?i, int ?j ); … … 3480 3481 3481 3482 \CFA named and default arguments are backwards compatible with C. 3482 \Index*[C++]{\CC{}} only supports default arguments;3483 \Index*{Ada} supports both named and default arguments.3483 \Index*[C++]{\CC{}} only supports default parameters; 3484 \Index*{Ada} supports both named and default parameters. 3484 3485 3485 3486
Note: See TracChangeset
for help on using the changeset viewer.