girparser: Better support for arrays in return type.
[vala-lang.git] / doc / vala / types.xml
blob8b383f48d33d5798262a5b518d0eebd117549829
1 <?xml version="1.0"?>
2 <section id="types">
3         <h>Types</h>
4         <p>Vala supports four kinds of data types: value types, reference types, type parameters, and pointer types. Value types include simple types (e.g. char, int, and float), enum types, array types, and struct types. Reference types include object types, delegate types, and error types. Type parameters are parameters used in generic types.</p>
5         <p>Value types differ from reference types in that variables of the value types directly contain their data, whereas variables of the reference types store references to their data, the latter being known as objects. With reference types, it is possible for two variables to reference the same object, and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other.</p>
6         <blockquote>
7 type:
8         value-type
9         reference-type
10         nullable-type
11         type-parameter
12         pointer-type
13         </blockquote>
14         <section id="valuetypes">
15                 <h>Value types</h>
16                 <p>Instances of value types are stored directly in variables.  They are duplicated whenever assigned to another variable (e.g. passed to a method).  For local variables, value types are stored on the stack.</p>
17                 <blockquote>
18 value-type:
19         struct-type
20         enum-type
21         array-type
23 struct-type:
24         type-name
25         integral-type
26         floating-point-type
27         <l>bool</l>
29 integral-type:
30         <l>char</l>
31         <l>uchar</l>
32         <l>short</l>
33         <l>ushort</l>
34         <l>int</l>
35         <l>uint</l>
36         <l>long</l>
37         <l>ulong</l>
38         <l>size_t</l>
39         <l>ssize_t</l>
40         <l>int8</l>
41         <l>uint8</l>
42         <l>int16</l>
43         <l>uint16</l>
44         <l>int32</l>
45         <l>uint32</l>
46         <l>int64</l>
47         <l>uint64</l>
48         <l>unichar</l>
50 floating-point-type:
51         <l>float</l>
52         <l>double</l>
54 enum-type:
55         type-name
57 array-type:
58         non-array-type <l>[]</l>
59         non-array-type <l>[</l> dim-seperators <l>]</l>
61 non-array-type:
62         value-type
63         object-type
64         class-type
65         delegate-type
66         error-type
68 dim-separators:
69         <l>,</l>
70         dim-separators <l>,</l>
71                 </blockquote>
72                 <section id="structtypes">
73                         <h>Struct types</h>
74                         <p>Documentation</p>
75                 </section>
76                 <section id="simpletypes">
77                         <h>Simple types</h>
78                         <p>Documentation</p>
79                 </section>
80                 <section id="integraltypes">
81                         <h>Integral types</h>
82                         <p>Documentation</p>
83                 </section>
84                 <section id="floatingpointtypes">
85                         <h>Floating point types</h>
86                         <p>Documentation</p>
87                 </section>
88                 <section id="booltype">
89                         <h>The bool type</h>
90                         <p>Documentation</p>
91                 </section>
92                 <section id="enumtypes">
93                         <h>Enumeration types</h>
94                         <p>An enumeration type is a type containing named constants.</p>
95                         <p>See enums.</p>
96                 </section>
97         </section>
98         <section id="referencetypes">
99                 <h>Reference types</h>
100                 <p>Instances of reference types are always stored on the heap. Variables contain references to them. Assigning to another variable duplicates reference, not object.</p>
101                 <blockquote>
102 reference-type:
103         object-type
104         class-type
105         delegate-type
106         error-type
107         weak-reference-type
109 weak-reference-type:
110         <l>weak</l> object-type
111         <l>weak</l> class-type
112         <l>weak</l> array-type
113         <l>weak</l> delegate-type
114         <l>weak</l> error-type
116 object-type:
117         type-name
118         <l>string</l>
120 class-type:
121         type-name <l>. Class</l>
123 delegate-type:
124         type-name
126 error-type:
127         type-name
128                 </blockquote>
129                 <section id="weakreferencetypes">
130                         <h>Weak reference types</h>
131                         <p>Documentation</p>
132                 </section>
133                 <section id="arraytypes">
134                         <h>Array types</h>
135                         <p>An array is a data structure that contains zero or more elements of the same type.</p>
136                 </section>
137                 <section id="delegatetypes">
138                         <h>Delegate types</h>
139                         <p>A delegate is a data structure that refers to a method, and for instance methods, it also refers to the corresponding object instance.</p>
140                 </section>
141                 <section id="errortypes">
142                         <h>Error types</h>
143                         <p>Instances of error types represent recoverable runtime errors.</p>
144                 </section>
145         </section>
146         <section id="nullabletypes">
147                 <h>Nullable types</h>
148                 <p>An instance of a nullable type <code>T?</code> can either be a value of type <code>T</code> or <code>null</code>.</p>
149                 <blockquote>
150 nullable-type:
151         value-type <l>?</l>
152         reference-type <l>?</l>
153                 </blockquote>
154         </section>
155         <section id="pointertypes">
156                 <h>Pointer types</h>
157                 <p>Unlike references, pointers are not tracked by the memory manager. The value of a pointer having type T* represents the address of a variable of type T. The pointer indirection operator * can be used to access this variable. Like a nullable object reference, a pointer can be null. The <code>void*</code> type represents a pointer to an unknown type. As the referent type is unknown, the indirection operator cannot be applied to a pointer of type <code>void*</code>, nor can any arithmetic be performed on such a pointer. However, a pointer of type <code>void*</code> can be cast to any other pointer type (and vice versa) and compared to values of other pointer types.</p>
158                 <blockquote>
159 pointer-type:
160         type-name <l>*</l>
161         pointer-type <l>*</l>
162         <l>void*</l>
163                 </blockquote>
164         </section>
165 </section>