@@ -7806,12 +7806,32 @@ <h3 id="Min_and_max">Min and max</h3>
7806
7806
< h3 id ="Allocation "> Allocation</ h3 >
7807
7807
7808
7808
< p >
7809
- The built-in function < code > new</ code > takes a type < code > T</ code > ,
7810
- allocates storage for a < a href ="#Variables "> variable</ a > of that type
7811
- at run time, and returns a value of type < code > *T</ code >
7812
- < a href ="#Pointer_types "> pointing</ a > to it.
7813
- The variable is initialized as described in the section on
7814
- < a href ="#The_zero_value "> initial values</ a > .
7809
+ The built-in function < code > new</ code > creates a new, initialized
7810
+ < a href ="#Variables "> variable</ a > and returns
7811
+ a < a href ="#Pointer_types "> pointer</ a > to it.
7812
+
7813
+ It accepts a single argument, which may be either an expression or a type.
7814
+ </ p >
7815
+ < p >
7816
+ If the argument < code > expr</ code > is an expression of
7817
+ type < code > T</ code > , or an untyped constant expression
7818
+ whose < a href ="#Constants "> default type</ a > is < code > T</ code > ,
7819
+ then < code > new(expr)</ code > allocates a variable of
7820
+ type < code > T</ code > , initializes it to the value
7821
+ of < code > expr</ code > , and returns its address, a value of
7822
+ type < code > *T</ code > .
7823
+ </ p >
7824
+ < p >
7825
+ If the argument is a type < code > T</ code > , then < code > new(T)</ code >
7826
+ allocates a variable initialized to
7827
+ the < a href ="#The_zero_value "> zero value</ a > of type < code > T</ code > .
7828
+ </ p >
7829
+ < p >
7830
+ For example, < code > new(123)</ code > and < code > new(int)</ code > each
7831
+ return a pointer to a new variable of type < code > int</ code > .
7832
+
7833
+ The value of the first variable is < code > 123</ code > , and the value
7834
+ of the second is < code > 0</ code > .
7815
7835
</ p >
7816
7836
7817
7837
< pre class ="grammar ">
0 commit comments