summaryrefslogtreecommitdiff
path: root/doc/manual/types.xml
blob: 8b383f48d33d5798262a5b518d0eebd117549829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?xml version="1.0"?>
<section id="types">
	<h>Types</h>
	<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>
	<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>
	<blockquote>
type:
	value-type
	reference-type
	nullable-type
	type-parameter
	pointer-type
	</blockquote>
	<section id="valuetypes">
		<h>Value types</h>
		<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>
		<blockquote>
value-type:
	struct-type
	enum-type
        array-type

struct-type:
	type-name
	integral-type
	floating-point-type
	<l>bool</l>

integral-type:
	<l>char</l>
	<l>uchar</l>
	<l>short</l>
	<l>ushort</l>
	<l>int</l>
	<l>uint</l>
	<l>long</l>
	<l>ulong</l>
	<l>size_t</l>
	<l>ssize_t</l>
	<l>int8</l>
	<l>uint8</l>
	<l>int16</l>
	<l>uint16</l>
	<l>int32</l>
	<l>uint32</l>
	<l>int64</l>
	<l>uint64</l>
	<l>unichar</l>

floating-point-type:
	<l>float</l>
	<l>double</l>

enum-type:
	type-name

array-type:
	non-array-type <l>[]</l>
	non-array-type <l>[</l> dim-seperators <l>]</l>

non-array-type:
	value-type
	object-type
	class-type
	delegate-type
	error-type

dim-separators:
	<l>,</l>
	dim-separators <l>,</l>
		</blockquote>
		<section id="structtypes">
			<h>Struct types</h>
			<p>Documentation</p>
		</section>
		<section id="simpletypes">
			<h>Simple types</h>
			<p>Documentation</p>
		</section>
		<section id="integraltypes">
			<h>Integral types</h>
			<p>Documentation</p>
		</section>
		<section id="floatingpointtypes">
			<h>Floating point types</h>
			<p>Documentation</p>
		</section>
		<section id="booltype">
			<h>The bool type</h>
			<p>Documentation</p>
		</section>
		<section id="enumtypes">
			<h>Enumeration types</h>
			<p>An enumeration type is a type containing named constants.</p>
			<p>See enums.</p>
		</section>
	</section>
	<section id="referencetypes">
		<h>Reference types</h>
		<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>
		<blockquote>
reference-type:
	object-type
	class-type
	delegate-type
	error-type
	weak-reference-type

weak-reference-type:
	<l>weak</l> object-type
	<l>weak</l> class-type
	<l>weak</l> array-type
	<l>weak</l> delegate-type
	<l>weak</l> error-type

object-type:
	type-name
	<l>string</l>

class-type:
	type-name <l>. Class</l>

delegate-type:
	type-name

error-type:
	type-name
		</blockquote>
		<section id="weakreferencetypes">
			<h>Weak reference types</h>
			<p>Documentation</p>
		</section>
		<section id="arraytypes">
			<h>Array types</h>
			<p>An array is a data structure that contains zero or more elements of the same type.</p>
		</section>
		<section id="delegatetypes">
			<h>Delegate types</h>
			<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>
		</section>
		<section id="errortypes">
			<h>Error types</h>
			<p>Instances of error types represent recoverable runtime errors.</p>
		</section>
	</section>
	<section id="nullabletypes">
		<h>Nullable types</h>
		<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>
		<blockquote>
nullable-type:
	value-type <l>?</l>
	reference-type <l>?</l>
		</blockquote>
	</section>
	<section id="pointertypes">
		<h>Pointer types</h>
		<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>
		<blockquote>
pointer-type:
	type-name <l>*</l>
	pointer-type <l>*</l>
	<l>void*</l>
		</blockquote>
	</section>
</section>