File: AA-5-4.html

package info (click to toggle)
ada-reference-manual 20021112web-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 18,652 kB
  • ctags: 8,921
  • sloc: makefile: 52; sh: 20
file content (314 lines) | stat: -rw-r--r-- 23,871 bytes parent folder | download
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <TITLE>AARM95 - Case Statements</TITLE>
    <META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
    <META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
    <STYLE type="text/css">
    DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
    TT {font-family: "Courier New", monospace}
    DT {display: compact}
    DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
    DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
    DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
    DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
    DIV.Index {font-family: "Times New Roman", Times, serif}
    DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
    DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
    DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
    DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
    DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
    DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
    DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left:  10.0em; margin-bottom: 0.6em}
    DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
    DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
    DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
    DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
    DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left:  15.0em; margin-bottom: 0.6em}
    UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
    DD.Hanging {margin-left: 6.0em}
    DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.IndentedHanging {margin-left: 2.0em}
    DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.HangingInBulleted {margin-left: 4.0em}
    DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.SmallHanging {margin-left: 7.5em}
    DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.SmallIndentedHanging {margin-left: 2.0em}
    DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.SmallHangingInBulleted {margin-left: 5.0em}
    DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.Enumerated {margin-left: 2.0em}
    DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.SmallEnumerated {margin-left: 2.5em}
    DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    </STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-5-3.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-5-5.html">Next</A></P>
<HR>
<H1> 5.4 Case Statements</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;[A <FONT FACE="Arial, Helvetica">case_statement</FONT>
selects for execution one of a number of alternative <FONT FACE="Arial, Helvetica">sequences_of_statements</FONT>;
the chosen alternative is defined by the value of an expression.] </DIV>

<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">case_statement<A NAME="I2950"></A>
::= </FONT><BR>
&nbsp;&nbsp;&nbsp;<B>case</B>&nbsp;<A NAME="I2951"></A><FONT FACE="Arial, Helvetica">expression</FONT>&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I2952"></A><FONT FACE="Arial, Helvetica">case_statement_alternative</FONT><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<A NAME="I2953"></A><FONT FACE="Arial, Helvetica">case_statement_alternative</FONT>}<BR>
&nbsp;&nbsp;&nbsp;<B>end</B>&nbsp;<B>case</B>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">case_statement_alternative<A NAME="I2954"></A>
::= </FONT><BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;<A NAME="I2955"></A><FONT FACE="Arial, Helvetica">discrete_choice_list</FONT>&nbsp;=&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I2956"></A><FONT FACE="Arial, Helvetica">sequence_of_statements</FONT></DIV>

<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I2957"></A>The <FONT FACE="Arial, Helvetica">expression</FONT>
is expected to be of any discrete type. <A NAME="I2958"></A>The expected
type for each <FONT FACE="Arial, Helvetica">discrete_choice</FONT> is
the type of the <FONT FACE="Arial, Helvetica">expression</FONT>. </DIV>

<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;The <FONT FACE="Arial, Helvetica">expression</FONT>s
and <FONT FACE="Arial, Helvetica">discrete_range</FONT>s given as <FONT FACE="Arial, Helvetica">discrete_choice</FONT>s
of a <FONT FACE="Arial, Helvetica">case_statement</FONT> shall be static.
[A <FONT FACE="Arial, Helvetica">discrete_choice</FONT> <B>others</B>,
if present, shall appear alone and in the last <FONT FACE="Arial, Helvetica">discrete_choice_list</FONT>.]</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;The possible values of the <FONT FACE="Arial, Helvetica">expression</FONT>
shall be covered as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If the <FONT FACE="Arial, Helvetica">expression</FONT>
is a <FONT FACE="Arial, Helvetica">name</FONT> [(including a <FONT FACE="Arial, Helvetica">type_conversion</FONT>
or a <FONT FACE="Arial, Helvetica">function_call</FONT>)] having a static
and constrained nominal subtype, or is a <FONT FACE="Arial, Helvetica">qualified_expression</FONT>
whose <FONT FACE="Arial, Helvetica">subtype_mark</FONT> denotes a static
and constrained scalar subtype, then each non-<B>others</B> <FONT FACE="Arial, Helvetica">discrete_choice</FONT>
shall cover only values in that subtype, and each value of that subtype
shall be covered by some <FONT FACE="Arial, Helvetica">discrete_choice</FONT>
[(either explicitly or by <B>others</B>)]. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Although
not official <FONT FACE="Arial, Helvetica">name</FONT>s of objects, a
value conversion still has a defined nominal subtype, namely its target
subtype. See <A HREF="AA-4-6.html">4.6</A>. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If the type of the <FONT FACE="Arial, Helvetica">expression</FONT>
is <I>root_integer</I>, <I>universal_integer</I>, or a descendant of
a formal scalar type, then the <FONT FACE="Arial, Helvetica">case_statement</FONT>
shall have an <B>others</B> <FONT FACE="Arial, Helvetica">discrete_choice</FONT>.
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>8.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This is because
the base range is implementation defined for <I>root_integer</I> and
<I>universal_integer</I>, and not known statically in the case of a formal
scalar type. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>Otherwise, each value of the base range of the type of
the <FONT FACE="Arial, Helvetica">expression</FONT> shall be covered
[(either explicitly or by <B>others</B>)]. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;Two distinct <FONT FACE="Arial, Helvetica">discrete_choice</FONT>s
of a <FONT FACE="Arial, Helvetica">case_statement</FONT> shall not cover
the same value. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The goal
of these coverage rules is that any possible value of the <FONT FACE="Arial, Helvetica">expression</FONT>
of a <FONT FACE="Arial, Helvetica">case_statement</FONT> should be covered
by exactly one <FONT FACE="Arial, Helvetica">discrete_choice</FONT> of
the <FONT FACE="Arial, Helvetica">case_statement</FONT>, and that this
should be checked at compile time. The goal is achieved in most cases,
but there are two minor loopholes: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.b</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>If the expression reads an object with an invalid representation
(e.g. an uninitialized object), then the value can be outside the covered
range. This can happen for static constrained subtypes, as well as nonstatic
or unconstrained subtypes. It cannot, however, happen if the <FONT FACE="Arial, Helvetica">case_statement</FONT>
has the <FONT FACE="Arial, Helvetica">discrete_choice</FONT> <B>others</B>,
because <B>others</B> covers all values, even those outside the subtype.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.c</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>If the compiler chooses to represent the value of an expression
of an unconstrained subtype in a way that includes values outside the
bounds of the subtype, then those values can be outside the covered range.
For example, if X: Integer := Integer'Last;, and the case <FONT FACE="Arial, Helvetica">expression</FONT>
is X+1, then the implementation might choose to produce the correct value,
which is outside the bounds of Integer. (It might raise Constraint_Error
instead.) This case can only happen for non-generic subtypes that are
either unconstrained or non-static (or both). It can only happen if there
is no <B>others</B> <FONT FACE="Arial, Helvetica">discrete_choice</FONT>.
</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In the uninitialized variable
case, the value might be anything; hence, any alternative can be chosen,
or Constraint_Error can be raised. (We intend to prevent, however, jumping
to random memory locations and the like.) In the out-of-range case, the
behavior is more sensible: if there is an <B>others</B>, then the implementation
may choose to raise Constraint_Error on the evaluation of the <FONT FACE="Arial, Helvetica">expression</FONT>
(as usual), or it may choose to correctly evaluate the <FONT FACE="Arial, Helvetica">expression</FONT>
and therefore choose the <B>others</B> alternative. Otherwise (no <B>others</B>),
Constraint_Error is raised either way -- on the <FONT FACE="Arial, Helvetica">expression</FONT>
evaluation, or for the <FONT FACE="Arial, Helvetica">case_statement</FONT>
itself.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>For an enumeration type with a
discontiguous set of internal codes (see <A HREF="AA-13-4.html">13.4</A>),
the only way to get values in between the proper values is via an object
with an invalid representation; there is no ``out-of-range'' situation
that can produce them. </FONT></DIV>

<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I2959"></A>For the execution of a <FONT FACE="Arial, Helvetica">case_statement</FONT>
the <FONT FACE="Arial, Helvetica">expression</FONT> is first evaluated.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;If the value of the <FONT FACE="Arial, Helvetica">expression</FONT>
is covered by the <FONT FACE="Arial, Helvetica">discrete_choice_list</FONT>
of some <FONT FACE="Arial, Helvetica">case_statement_alternative</FONT>,
then the <FONT FACE="Arial, Helvetica">sequence_of_statements</FONT>
of the <FONT FACE="Arial, Helvetica">_alternative</FONT> is executed.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I2960"></A><A NAME="I2961"></A><A NAME="I2962"></A>Otherwise
(the value is not covered by any <FONT FACE="Arial, Helvetica">discrete_choice_list</FONT>,
perhaps due to being outside the base range), Constraint_Error is raised.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>In this case,
the value is outside the base range of its type, or is an invalid representation.</FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>5&nbsp;&nbsp;The execution of a <FONT FACE="Arial, Helvetica">case_statement</FONT>
chooses one and only one alternative. Qualification of the expression
of a <FONT FACE="Arial, Helvetica">case_statement</FONT> by a static
subtype can often be used to limit the number of choices that need be
given explicitly. </FONT></DIV>

<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;&nbsp;<I>Examples of
case statements:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Examples"><TT><B>case</B>&nbsp;Sensor&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Elevation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Record_Elevation(Sensor_Value);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Azimuth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Record_Azimuth&nbsp;&nbsp;(Sensor_Value);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Distance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Record_Distance&nbsp;(Sensor_Value);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;<B>others</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;<B>null</B>;<BR>
<B>end</B>&nbsp;<B>case</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Examples"><TT><B>case</B>&nbsp;Today&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Mon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Compute_Initial_Balance;<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Fri&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Compute_Closing_Balance;<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Tue&nbsp;..&nbsp;Thu&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Generate_Report(Today);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;Sat&nbsp;..&nbsp;Sun&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;<B>null</B>;<BR>
<B>end</B>&nbsp;<B>case</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Examples"><TT><B>case</B>&nbsp;Bin_Number(Count)&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Update_Bin(1);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;Update_Bin(2);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;3&nbsp;|&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;=&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Empty_Bin(1);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Empty_Bin(2);<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;<B>others</B>&nbsp;&nbsp;&nbsp;=&gt;&nbsp;<B>raise</B>&nbsp;Error;<BR>
<B>end</B>&nbsp;<B>case</B>;</TT></DIV>

<H4 ALIGN=CENTER>Incompatibilities With Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>18.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><U><A NAME="I2963"></A>In Ada
95, <FONT FACE="Arial, Helvetica">function_call</FONT>s and <FONT FACE="Arial, Helvetica">type_conversion</FONT>s
are <FONT FACE="Arial, Helvetica">name</FONT>s, whereas in Ada 83, they
were <FONT FACE="Arial, Helvetica">expression</FONT>s. Therefore, if
the <FONT FACE="Arial, Helvetica">expression</FONT> of a <FONT FACE="Arial, Helvetica">case_statement</FONT>
is a <FONT FACE="Arial, Helvetica">function_call</FONT> or <FONT FACE="Arial, Helvetica">type_conversion</FONT>,
and the result subtype is static, it is illegal to specify a choice outside
the bounds of the subtype. For this case in Ada 83 choices only are required
to be in the base range of the type.</U></FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.a.2/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><U>In addition, the rule about
which choices must be covered is unchanged in Ada 95. Therefore, for
a <FONT FACE="Arial, Helvetica">case_statement</FONT> whose <FONT FACE="Arial, Helvetica">expression</FONT>
is a <FONT FACE="Arial, Helvetica">function_call</FONT> or <FONT FACE="Arial, Helvetica">type_conversion</FONT>,
Ada 83 required covering all choices in the base range, while Ada 95
only requires covering choices in the bounds of the subtype. If the <FONT FACE="Arial, Helvetica">case_statement</FONT>
does not include an <B>others</B> <FONT FACE="Arial, Helvetica">discrete_choice</FONT>,
then a legal Ada 83 <FONT FACE="Arial, Helvetica">case_statement</FONT>
will be illegal in Ada 95 if the bounds of the subtype are different
than the bounds of the base type.</U> </FONT></DIV>

<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2964"></A>In Ada 83,
the <FONT FACE="Arial, Helvetica">expression</FONT> in a <FONT FACE="Arial, Helvetica">case_statement</FONT>
is not allowed to be of a generic formal type. This restriction is removed
in Ada 95; an <B>others</B> <FONT FACE="Arial, Helvetica">discrete_choice</FONT>
is required instead.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In Ada 95, a function call is
the name of an object; this was not true in Ada 83 (see <A HREF="AA-4-1.html">4.1</A>,
``<A HREF="AA-4-1.html">Names</A>''). This change makes the following
<FONT FACE="Arial, Helvetica">case_statement</FONT> legal: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.c</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>subtype</B>&nbsp;S&nbsp;<B>is</B>&nbsp;Integer&nbsp;<B>range</B>&nbsp;1..2;<BR>
<B>function</B>&nbsp;F&nbsp;<B>return</B>&nbsp;S;<BR>
<B>case</B>&nbsp;F&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;1&nbsp;=&gt;&nbsp;...;<BR>
&nbsp;&nbsp;&nbsp;<B>when</B>&nbsp;2&nbsp;=&gt;&nbsp;...;<BR>
&nbsp;&nbsp;&nbsp;--<I>&nbsp;No&nbsp;<B>others</B>&nbsp;needed.</I><BR>
<B>end</B>&nbsp;<B>case</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that the result subtype given
in a function <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>
is ignored; for a <FONT FACE="Arial, Helvetica">case_statement</FONT>
whose expression calls a such a function, the full coverage rules are
checked using the result subtype of the original function. Note that
predefined operators such as &quot;+&quot; have an unconstrained result
subtype (see <A HREF="AA-4-5-1.html">4.5.1</A>). Note that generic formal
functions do not have static result subtypes. Note that the result subtype
of an inherited subprogram need not correspond to any namable subtype;
there is still a perfectly good result subtype, though. </FONT></DIV>

<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>18.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Ada 83 forgot to say what happens
for ``legally'' out-of-bounds values.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.f</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We take advantage of rules and
terms (e.g. <I>cover a value</I>) defined for <FONT FACE="Arial, Helvetica">discrete_choice</FONT>s
and <FONT FACE="Arial, Helvetica">discrete_choice_list</FONT>s in <A HREF="AA-3-8-1.html">3.8.1</A>,
``<A HREF="AA-3-8-1.html">Variant Parts and Discrete Choices</A>''.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In the Name Resolution Rule for
the case expression, we no longer need RM83-5.4(3)'s ``which must be
determinable independently of the context in which the expression occurs,
but using the fact that the expression must be of a discrete type,''
because the <FONT FACE="Arial, Helvetica">expression</FONT> is now a
complete context. See <A HREF="AA-8-6.html">8.6</A>, ``<A HREF="AA-8-6.html">The
Context of Overload Resolution</A>''.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.h</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Since <FONT FACE="Arial, Helvetica">type_conversion</FONT>s
are now defined as <FONT FACE="Arial, Helvetica">name</FONT>s, their
coverage rule is now covered under the general rule for <FONT FACE="Arial, Helvetica">name</FONT>s,
rather than being separated out along with <FONT FACE="Arial, Helvetica">qualified_expression</FONT>s.
</FONT></DIV>

<HR>
<P><A HREF="AA-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-5-3.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-5-5.html">Next</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>