Debian Codegraph @

source_2012/13a.mss

raw
1 @Part(13, Root="ada.mss")
2
3 @Comment{$Date: 2015/04/03 04:12:42 $}
4 @LabeledSection{Representation Issues}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/13a.mss,v $}
7 @Comment{$Revision: 1.113 $}
8
9 @begin{Intro}
10 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
11 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
12 @redundant[This @Chg{Version=[3],New=[clause],Old=[section]} describes features for
13 querying and controlling @Chg{New=[certain aspects of entities],
14 Old=[aspects of representation]} and for interfacing to hardware.]
15 @end{Intro}
16
17 @begin{DiffWord83}
18 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
19 The @Chg{Version=[3],New=[subclauses],Old=[clauses]} of this
20 @Chg{Version=[3],New=[clause],Old=[section]} have been reorganized.
21 This was necessary to preserve a logical order,
22 given the new Ada 95 semantics given in this section.
23 @end{DiffWord83}
24
25 @LabeledRevisedClause{Version=[3],New=[Operational and Representation Aspects],Old=[Representation Items]}
26 @Comment{@LabeledRevisedClause{Version=[1],New=[Operational and Representation Items],Old=[Representation Items]} Don't have a way to include the middle title}
27
28 @begin{Intro}
29 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
30 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
31 @ChgAdded{Version=[1],Text=[@Redundant[@Chg{Version=[3],New=[@Defn{aspect}],
32 Old=[Representation and operational items can be used to specify aspects of
33 entities. ]}Two kinds of aspects of entities can be specified:
34 @Chg{Version=[3],New=[],Old=[aspects of ]}representation@Chg{Version=[3],
35 New=[ aspects],Old=[]} and operational aspects. Representation
36 @Chg{Version=[3],New=[aspects affect],Old=[items specify]}
37 how the types and other entities of the language are to be mapped onto
38 the underlying machine. Operational @Chg{Version=[3],New=[aspects determine],
39 Old=[items specify]} other properties of entities.]]}
40
41 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1],ARef=[AI05-0295-1]}
42 @ChgAdded{Version=[1],Text=[@Redundant[Either kind of aspect of an entity may be
43 specified by means of an @nt{aspect_specification} (see @RefSecNum{Aspect Specifications}),
44 which is an optional element
45 of most kinds of declarations and applies to the entity or entities being
46 declared. Aspects may also be specified by certain other constructs occurring
47 subsequent to the declaration of the affected entity: a representation aspect
48 value may be specified by means of a representation item
49 and an operational aspect value may be specified by means of an
50 operational item.]]}
51
52 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
53 @Defn{representation item}
54 @RootDefn{representation pragma}
55 @RootDefn{pragma, representation}
56 There are @Chg{New=[six],Old=[three]} kinds of @i{representation items}:
57 @Chg{New=[@nt{attribute_@!definition_@!clause}s for representation attributes,
58 @nt{enumeration_@!representation_@!clause}s,
59 @nt{record_@!representation_@!clause}s, @nt{at_clause}s, ],
60 Old=[@nt{representation_@!clause}s, ]}@nt<component_clause>s, and
61 @i{representation pragmas}.
62 @Redundant[@Chg{New=[],Old=[Representation items specify how the types and other entities of
63 the language are to be mapped onto the underlying machine.]}
64 They can be provided to give more efficient representation or to
65 interface with features that are outside the domain of the language
66 (for example, peripheral hardware).
67 @Chg{New=[],Old=[Representation items also specify other specifiable
68 properties of entities.
69 A representation item applies to an entity identified by
70 a @nt<local_name>, which denotes an entity declared local to the
71 current declarative region, or a library unit declared immediately
72 preceding a representation pragma in a @nt<compilation>.]}]
73
74 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
75 @ChgAdded{Version=[1],Text=[An @Defn{operational item}@i<operational item> is an
76 @nt<attribute_definition_clause> for an operational attribute.]}
77
78 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
79 @ChgAdded{Version=[1],Text=[@Redundant[An operational item or a representation
80 item applies to an entity identified by a @nt<local_name>, which denotes an
81 entity declared local to the current declarative region, or a library unit
82 declared immediately preceding a representation pragma in a
83 @nt<compilation>.]]}
84 @end{Intro}
85
86 @begin{Metarules}
87 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
88 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
89 @ChgAdded{Version=[1],Text=[@Chg{Version=[3],New=[Representation
90 aspects],Old=[Aspects of representation]} are intended to refer to
91 properties that need to be known before the compiler can generate code to
92 create or access an entity. For instance, the size of an object needs to be
93 known before the object can be created. Conversely, operational aspects are
94 those that only need to be known before they can be used. For instance, how an
95 object is read from a stream only needs to be known when a stream read is
96 executed. Thus, @Chg{Version=[3],New=[],Old=[aspects of
97 ]}representation@Chg{Version=[3], New=[ aspects],Old=[]} have stricter rules as
98 to when they can be specified.]}
99
100 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
101 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
102 @ChgAdded{Version=[2],Text=[Confirming the value of an aspect
103 @Chg{Version=[3],New=[],Old=[with an operational or representation item ]}should
104 never change the semantics of
105 the aspect. Thus Size = 8 (for example) means the same thing whether it
106 was specified with a representation item or whether the compiler chose this
107 value by default.]}
108 @end{Metarules}
109
110 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Aspect>,
111 Text=<@ChgAdded{Version=[3],Text=[An aspect is
112 a specifiable property of an entity. An aspect may be specified by an
113 @nt{aspect_specification} on the declaration of the entity. Some aspects may be
114 queried via attributes.]}>}
115
116 @begin{Syntax}
117 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
118 @Syn{lhs=<@Chg{New=[aspect_clause],Old=[representation_clause]}>,rhs="@Syn2{attribute_definition_clause}
119 | @Syn2{enumeration_representation_clause}
120 | @Syn2{record_representation_clause}
121 | @Syn2{at_clause}"}
122
123 @Syn{lhs=<local_name>,rhs="@Syn2{direct_name}
124 | @Syn2{direct_name}@SingleQuote@Syn2{attribute_designator}
125 | @SynI{library_unit_}@Syn2{name}"}
126
127 @begin{SyntaxText}
128 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
129 A representation pragma is allowed only at places where
130 @Chg{New=[an @nt{aspect_clause}],Old=[a @nt{representation_clause}]}
131 or @nt{compilation_unit} is allowed.
132 @Chg{New=[@IndexSee(Term=(representation_clause),See=(aspect_clause))],Old=[]}
133 @end{SyntaxText}
134 @end{Syntax}
135
136 @begin{Resolution}
137 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
138 In @Chg{New=[an operational item or],Old=[a]} representation item,
139 if the @nt<local_name> is a @nt<direct_name>, then it shall
140 resolve to denote a declaration
141 (or, in the case of a @nt{pragma}, one or more declarations)
142 that occurs immediately within the same
143 declarative region as the @Chg{New=[],Old=[representation ]}item.
144 If the @nt<local_name> has an @nt<attribute_designator>, then it shall
145 resolve to denote an implementation-defined
146 component (see @RefSecNum{Record Representation Clauses})
147 or a class-wide
148 type implicitly declared immediately within the same
149 declarative region as the @Chg{New=[],Old=[representation ]}item.
150 A @nt<local_name> that is a @i{library_unit_}@nt<name> (only
151 permitted in a representation pragma) shall resolve
152 to denote the @nt<library_item> that immediately precedes
153 (except for other pragmas) the representation pragma.
154 @begin{Reason}
155 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
156 This is a @ResolutionName,
157 because we don't want @Chg{New=[an operational or],Old=[a]} representation
158 item for X to be ambiguous just because there's another X declared in an outer
159 declarative region.
160 It doesn't make much difference, since most
161 @Chg{New=[operational or ],Old=[]}representation items are for types or
162 subtypes, and type and subtype names can't be overloaded.
163 @end{Reason}
164 @begin{Ramification}
165 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
166 The visibility rules imply that the declaration has to occur
167 before the @Chg{New=[operational or ],Old=[]}representation item.
168
169 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
170 For objects, this implies that @Chg{New=[operational or ],Old=[]}representation items can be
171 applied only to stand-alone objects.
172 @end{Ramification}
173 @end{Resolution}
174
175 @begin{Legality}
176 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
177 The @nt{local_name} of @Chg{New=[an @nt<aspect_clause>],
178 Old=[a @nt<representation_clause>]} or representation pragma shall
179 statically denote an entity (or, in the case of a @nt{pragma},
180 one or more entities) declared immediately preceding it in a @nt<compilation>,
181 or within the same @nt{declarative_@!part}, @nt{package_@!specification},
182 @nt{task_@!definition}, @nt{protected_@!definition}, or
183 @nt{record_@!definition} as the representation @Chg{New=[or operational ],Old=[]}item.
184 If a @nt<local_name> denotes a @Redundant[local] callable entity,
185 it may do so through a @Redundant[local]
186 @nt<subprogram_@!renaming_@!declaration>
187 @Redundant[(as a way to resolve ambiguity in the presence of overloading)];
188 otherwise, the @nt<local_name> shall not denote a @nt<renaming_@!declaration>.
189 @begin{Ramification}
190 The @lquotes@;statically denote@rquotes@; part
191 implies that it is impossible to specify the representation of
192 an object that is not a stand-alone object,
193 except in the case of a representation
194 item like pragma Atomic
195 that is allowed inside a @nt{component_list}
196 (in which case the representation item specifies
197 the representation of components of all objects of the type).
198 It also prevents the problem of
199 renamings of things like @lquotes@;P.@key[all]@rquotes@;
200 (where P is an access-to-subprogram value)
201 or @lquotes@;E(I)@rquotes@; (where E is an entry family).
202
203 The part about where the denoted entity has to have been
204 declared appears twice @em once as a @ResolutionName,
205 and once as a @LegalityName.
206 Suppose P renames Q,
207 and we have a representation item in a @nt{declarative_part}
208 whose @nt<local_name> is P.
209 The fact that the representation item has to appear in the same
210 @nt{declarative_part} as P is a @ResolutionName,
211 whereas the fact that the representation item has to appear in the
212 same @nt{declarative_part} as Q is a @LegalityName.
213 This is subtle, but it seems like the least confusing set of rules.
214 @end{Ramification}
215 @begin{Discussion}
216 A separate @LegalityName applies for @nt<component_clause>s.
217 See @RefSec{Record Representation Clauses}.
218 @end{Discussion}
219
220 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
221 @Defn{representation of an object}
222 @Defn2{Term=[size], Sec=(of an object)}The @i{representation} of an
223 object consists of a certain
224 number of bits (the @i(size) of
225 the object).
226 @Chg{Version=[2],New=[For an object of an elementary type, these],Old=[These]}
227 are the bits that are normally read
228 or updated by the machine code
229 when loading, storing, or operating-on the value of the object.
230 @Chg{Version=[2],New=[For an object of a composite type, these
231 are the bits reserved for this object, and include bits occupied by
232 subcomponents of the object. If],Old=[This includes some padding bits, when]}
233 the size of @Chg{Version=[2],New=[an],Old=[the]} object
234 is greater than @Chg{Version=[2],New=[that],Old=[the size]} of its subtype@Chg{Version=[2],
235 New=[, the additional bits are padding bits.],Old=[.
236 @Defn{gaps}]}
237 @Defn{padding bits}
238 @Chg{Version=[2],New=[For an elementary object, these],Old=[Such]} padding bits
239 @Chg{Version=[2],New=[],Old=[are considered to be part of the representation of the
240 object, rather than being gaps between objects,
241 if these bits ]}are normally read and updated@Chg{Version=[2],New=[ along
242 with the others. For a
243 composite object, padding bits might not be read or updated in any given
244 composite operation, depending on the implementation],Old=[]}.
245
246 @begin{Honest}
247 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
248 @PDefn{contiguous representation}
249 @PDefn{discontiguous representation}
250 Discontiguous representations are allowed,
251 but the ones we're interested in here are generally contiguous
252 sequences of bits.@Chg{Version=[2],New=[ For a discontiguous representation,
253 the size doesn't necessarily describe the @lquotes@;footprint@rquotes of
254 the object in memory (that is, the amount of space taken in the address space
255 for the object).],Old=[]}
256 @end{Honest}
257 @begin{Discussion}
258 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
259 @ChgAdded{Version=[2],Text=[In the case of composite objects, we want the
260 implementation to have the flexibility to either do operations
261 component-by-component, or with a block operation covering all of the bits. We
262 carefully avoid giving a preference in the wording. There is no requirement
263 for the choice to be documented, either, as the implementation can make that
264 choice based on many factors, and could make a different choice for different
265 operations on the same object.]}
266
267 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
268 @ChgAdded{Version=[2],Text=[In the case of a properly aligned, contiguous
269 object whose size is a multiple of the storage unit size, no other bits should
270 be read or updated as part of operating on the object. We don't say this
271 normatively because it would be difficult to normatively define
272 @lquotes@;properly aligned@rquotes or @lquotes@;contiguous@rquotes.]}
273 @end{Discussion}
274 @begin{Ramification}
275 @Leading@;Two objects with the same value do not necessarily have the same
276 representation.
277 For example, an implementation might represent False as zero and True
278 as any odd value.
279 Similarly, two objects (of the same type)
280 with the same sequence of bits do not necessarily have the
281 same value.
282 For example, an implementation might use a biased representation in
283 some cases but not others:
284 @begin{Example}
285 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
286 @key[subtype] S @key[is] Integer @key[range] 1..256;
287 @key[type] A @key[is] @key[array](Natural @key[range] 1..4) @key[of] S@Chg{Version=[3],New=[
288 @key[with] Pack],Old=[;
289 @key[pragma] Pack(A)]};
290 X : S := 3;
291 Y : A := (1, 2, 3, 4);
292 @end{Example}
293
294 The implementation might use a biased-by-1 representation for the
295 array elements, but not for X.
296 X and Y(3) have the same value, but different representation:
297 the representation of X is a sequence of (say) 32 bits: 0...011,
298 whereas the representation of Y(3) is a sequence of 8 bits:
299 00000010 (assuming a two's complement representation).
300
301 Such tricks are not required, but are allowed.
302 @end{Ramification}
303 @begin{Discussion}
304 The value of any padding bits is not specified by the language,
305 though for a numeric type, it will be much harder to properly implement
306 the predefined operations if the padding bits are not either all zero,
307 or a sign extension.
308 @end{Discussion}
309 @begin{Ramification}
310 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
311 For example, suppose S'Size = 2, and an object X is of subtype S.
312 If the machine code typically uses a 32-bit load instruction to load the
313 value of X, then X'Size should be 32, even though 30 bits of the value
314 are just zeros or sign-extension bits.
315 On the other hand, if the machine code typically masks out those 30
316 bits, then X'Size should be 2.
317 Usually, such masking only happens for components of a composite type
318 for which @Chg{Version=[3],New=[Pack],Old=[packing]}, Component_Size, or
319 record layout is specified.
320
321 Note, however, that the formal parameter of an instance of
322 Unchecked_Conversion is a special case.
323 Its Size is required to be the same as that of its subtype.
324
325 Note that we don't generally talk about the representation of a
326 value.
327 A value is considered to be an amorphous blob
328 without any particular representation.
329 An object is considered to be more concrete.
330 @end{Ramification}
331
332 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0112-1],ARef=[AI05-0295-1]}
333 @RootDefn{aspect of representation}
334 @Defn{representation aspect}
335 @Chg{Version=[3],New=[@Defn2{Term=[directly specified],
336 Sec=(of a representation aspect of an entity)}],
337 Old=[@Defn2{Term=[directly specified],
338 Sec=(of an aspect of representation of an entity)}]}
339 A representation item @i{directly specifies}
340 @Chg{Version=[3],New=[a @i{representation aspect}],
341 Old=[an @i{aspect of representation}]} of the entity denoted
342 by the @nt{local_name},
343 except in the case of a type-related representation item,
344 whose @nt{local_name} shall denote a first subtype,
345 and which directly specifies an aspect
346 of the subtype's type.
347 @RootDefn2{Term=[type-related], Sec=(representation item)}
348 @RootDefn2{term=[subtype-specific], Sec=(of a representation item)}
349 @RootDefn2{Term=[type-related], Sec=(aspect)}
350 @RootDefn2{term=[subtype-specific], Sec=(of an aspect)}
351 A representation item that names a subtype is either
352 @i(subtype-specific) (Size and Alignment clauses)
353 or @i{type-related} (all others).
354 @Redundant[Subtype-specific aspects may differ for
355 different subtypes of the same type.]
356
357 @begin{Honest}
358 @i{Type-related} and @i{subtype-specific} are defined likewise for
359 the corresponding aspects of representation.
360 @end{Honest}
361 @begin{Honest}
362 Some representation items directly specify more than one aspect.
363 @end{Honest}
364 @begin{Discussion}
365 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
366 For example, a @nt{pragma} Export
367 @Chg{Version=[3],New=[(see @RefSecNum{Interfacing Pragmas}) ],Old=[]}specifies the convention
368 of an entity,
369 and also specifies that it is exported.@Chg{Version=[3],New=[ Such items are
370 obsolescent; directly specifying
371 the associated aspects is preferred.],Old=[]}
372 @end{Discussion}
373 @begin{Ramification}
374 Each specifiable attribute constitutes a separate aspect.
375 An @nt{enumeration_representation_clause} specifies the coding aspect.
376 A @nt{record_representation_clause} (without the @nt{mod_clause})
377 specifies the record layout aspect.
378 Each representation pragma specifies a separate aspect.
379 @end{Ramification}
380 @begin{Reason}
381 We don't need to say that an @nt{at_clause} or a
382 @nt{mod_clause} specify separate aspects,
383 because these are equivalent to @nt{attribute_definition_clause}s.
384 See @RefSec{At Clauses}, and @RefSec{Mod Clauses}.
385
386 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0112-1]}
387 @ChgAdded{Version=[3],Text=[We give a default naming for representation
388 aspects of representation pragmas so we don't have to do that for every
389 pragma. Operational and representation attributes are given a default naming
390 in @RefSecNum{Operational and Representation Attributes}.
391 We don't want any anonymous aspects; that would make other rules
392 more difficult to write and understand.]}
393 @end{Reason}
394 @begin{Ramification}
395 @Leading@;The following representation items are type-related:
396 @begin{Itemize}
397 @nt{enumeration_representation_clause}
398
399 @nt{record_representation_clause}
400
401 Component_Size clause
402
403 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
404 @ChgDeleted{Version=[1],Text=[External_Tag clause]}
405
406 Small clause
407
408 Bit_Order clause
409
410 Storage_Pool clause
411
412 Storage_Size clause
413
414 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]}
415 @ChgAdded{Version=[2],Text=[Stream_Size clause]}
416
417 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
418 @ChgDeleted{Version=[1],Text=[Read clause]}
419
420 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
421 @ChgDeleted{Version=[1],Text=[Write clause]}
422
423 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
424 @ChgDeleted{Version=[1],Text=[Input clause]}
425
426 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
427 @ChgDeleted{Version=[1],Text=[Output clause]}
428
429 Machine_Radix clause
430
431 pragma Pack
432
433 pragmas Import, Export, and Convention (when applied to a type)
434
435 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
436 pragmas Atomic@Chg{Version=[3],New=[, Independent,],Old=[]} and Volatile
437 (when applied to a type)
438
439 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
440 pragmas Atomic_Components@Chg{Version=[3],New=[, Independent_Components,],Old=[]}
441 and Volatile_Components (when applied to @Chg{Version=[3],New=[a],Old=[an
442 array]} type)
443
444 pragma Discard_Names (when applied to an enumeration or tagged type)
445 @end{Itemize}
446
447 @Leading@;The following representation items are subtype-specific:
448 @begin{Itemize}
449 Alignment clause (when applied to a first subtype)
450
451 Size clause (when applied to a first subtype)
452 @end{Itemize}
453
454 @Leading@;The following representation items do not apply to subtypes,
455 so they are neither type-related nor subtype-specific:
456 @begin{Itemize}
457 Address clause (applies to objects and program units)
458
459 Alignment clause (when applied to an object)
460
461 Size clause (when applied to an object)
462
463 pragmas Import, Export, and Convention (when applied to anything other
464 than a type)
465
466 pragmas Atomic and Volatile (when applied to an object or a component)
467
468 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
469 pragmas Atomic_Components@Chg{Version=[3],New=[, Independent_Components,],Old=[]}
470 and Volatile_Components (when applied to an array object)
471
472 pragma Discard_Names (when applied to an exception)
473
474 pragma Asynchronous (applies to procedures)
475
476 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]}
477 @ChgAdded{Version=[2],Text=[pragma No_Return (applies to subprograms)]}
478 @end{Itemize}
479
480 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
481 @ChgAdded{Version=[3],Text=[While an @nt{aspect_specification} is not
482 a representation item, a similar categorization applies to the aspect
483 that corresponds to each of these representation items (along with
484 aspects that do not have associated representation items).]}
485 @end{Ramification}
486
487 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
488 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
489 @ChgAdded{Version=[1],Text=[An operational item @i<directly specifies> an @i<operational aspect>
490 of the @Chg{Version=[3],New=[entity],Old=[type of the subtype]} denoted by
491 the @nt{local_name}@Chg{Version=[3],New=[, except in
492 the case of a type-related operational item, whose @nt{local_name} shall
493 denote a first subtype, and which directly specifies an aspect of the
494 type of the subtype],Old=[. The @nt{local_name}
495 of an operational item shall denote a first subtype. An operational item that
496 names a subtype is type-related]}.
497 @RootDefn{operational aspect}
498 @Defn2{Term=[directly specified],
499 Sec=(of an operational aspect of an entity)}
500 @RootDefn2{Term=[type-related], Sec=(operational item)}
501 @Defn2{Term=[type-related], Sec=(aspect)}]}
502
503 @begin{Ramification}
504 @ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
505 @ChgAdded{Version=[1],Type=[Leading],Text=[The following operational items are
506 type-related:]}
507 @begin{Itemize}
508
509 @ChgRef{Version=[1],Kind=[AddedNormal]}
510 @ChgAdded{Version=[1],Text=[External_Tag clause]}
511
512 @ChgRef{Version=[1],Kind=[AddedNormal]}
513 @ChgAdded{Version=[1],Text=[Read clause]}
514
515 @ChgRef{Version=[1],Kind=[AddedNormal]}
516 @ChgAdded{Version=[1],Text=[Write clause]}
517
518 @ChgRef{Version=[1],Kind=[AddedNormal]}
519 @ChgAdded{Version=[1],Text=[Input clause]}
520
521 @ChgRef{Version=[1],Kind=[AddedNormal]}
522 @ChgAdded{Version=[1],Text=[Output clause]}
523
524 @end{Itemize}
525 @end{Ramification}
526
527
528 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
529 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0116-1]}
530 A representation item that directly specifies an aspect of a subtype or
531 type shall appear after the type is completely defined
532 (see @RefSecNum{Completions of Declarations}),
533 and before the subtype or type is frozen (see
534 @RefSecNum{Freezing Rules}).@Chg{Version=[4],New=[],Old=[ If a
535 representation item @Chg{Version=[3],New=[or @nt{aspect_specification} ],Old=[]}is
536 given that directly specifies an aspect of an
537 entity, then it is illegal to give another representation item
538 @Chg{Version=[3],New=[or @nt{aspect_specification} ],Old=[]}that
539 directly specifies the same aspect of the entity.]}
540 @begin{Ramification}
541 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
542 The fact that a representation item @Chg{New=[(or operational item,
543 see next paragraph) ],Old=[]}that directly specifies
544 an aspect of an entity is required to appear before the entity is frozen
545 prevents changing the representation of an entity
546 after using the entity in ways that require the representation to be known.
547 @end{Ramification}
548 @begin{Honest}
549 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
550 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0116-1]}
551 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[The rule preventing
552 multiple specification
553 is also intended to cover other ways to specify representation aspects,
554 such as obsolescent @nt{pragma} Priority. Priority is not a representation
555 pragma, and as such is neither a representation item nor an
556 @nt{aspect_specification}. Regardless, giving both a @nt{pragma} Priority
557 and an @nt{aspect_specification} for Priority is illegal. We didn't want
558 to complicate the wording solely to support obsolescent features.]}]}
559 @end{Honest}
560
561 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
562 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
563 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0116-1]}
564 @ChgAdded{Version=[1],Text=[An operational item that directly specifies an
565 aspect of @Chg{Version=[3],New=[an entity],Old=[a type]} shall appear before the
566 @Chg{Version=[3],New=[entity],Old=[type]} is frozen (see
567 @RefSecNum{Freezing Rules}).@Chg{Version=[4],New=[],Old=[ If an operational
568 item @Chg{Version=[3],New=[or
569 @nt{aspect_specification} ],Old=[]}is given that directly specifies an aspect of
570 @Chg{Version=[3],New=[an entity],Old=[a type]}, then it is illegal to give
571 another operational item @Chg{Version=[3],New=[or @nt{aspect_specification}
572 ],Old=[]}that directly specifies the same aspect of the
573 @Chg{Version=[3],New=[entity],Old=[type]}.]}]}
574 @begin{Ramification}
575 @ChgRef{Version=[1],Kind=[AddedNormal]}
576 @ChgAdded{Version=[1],Text=[Unlike representation items, operational
577 items can be specified on
578 partial views. Since they don't affect the representation, the full
579 declaration need not be known to determine their legality.]}
580 @end{Ramification}
581
582 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0116-1]}
583 @ChgAdded{Version=[4],Text=[If a representation item, operational item, or
584 @nt{aspect_specification} is given that directly specifies an aspect of an
585 entity, then it is illegal to give another representation item, operational
586 item, or @nt{aspect_specification} that directly specifies the same aspect of
587 the entity.]}
588
589 @begin{Ramification}
590 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0116-1]}
591 @ChgAdded{Version=[4],Text=[This rule applies to all aspects, not just
592 those that are operational aspects or representation aspects. For instance,
593 it applies to subtype predicates and type invariants.]}
594 @end{Ramification}
595 @begin{Honest}
596 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0116-1]}
597 @ChgAdded{Version=[4],Text=[This rule is also intended to cover other ways
598 to specify representation aspects,
599 such as obsolescent @nt{pragma} Priority. Priority is not a representation
600 pragma, and as such is neither a representation item nor an
601 @nt{aspect_specification}. Regardless, giving both a @nt{pragma} Priority
602 and an @nt{aspect_specification} for Priority is illegal. We didn't want
603 to complicate the wording solely to support obsolescent features.]}
604 @end{Honest}
605
606 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0106-1],ARef=[AI05-0295-1]}
607 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0116-1]}@Comment{Just a paragraph number change}
608 @ChgAdded{Version=[3],Text=[Unless otherwise specified, it is illegal to
609 specify an operational or representation aspect of a generic formal
610 parameter.]}
611 @begin{Reason}
612 @ChgRef{Version=[3],Kind=[AddedNormal]}
613 @ChgAdded{Version=[3],Text=[Specifying an aspect on a generic formal
614 parameter implies an added contract for a generic unit. That contract
615 needs to be defined via generic parameter matching rules, and, as
616 aspects vary widely, that has to be done for each such aspect. Since
617 most aspects do not need this complexity (including all language-defined
618 aspects as of this writing), we avoid the complexity by saying that
619 such contract-forming aspect specifications are banned unless the
620 rules defining them explicitly exist. Note that the method of specification
621 does not matter: @nt{aspect_specification}s, representation items,
622 and operational items are all covered by this (and similar) rules.]}
623 @end{Reason}
624
625 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
626 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0109-1]}
627 For an untagged derived type, @Chg{Version=[3],New=[it is illegal to
628 specify a],Old=[no]} type-related representation
629 @Chg{Version=[3],New=[aspect],Old=[items are allowed]} if the parent type is a
630 by-reference type, or has any user-defined primitive
631 subprograms.@Chg{Version=[4],New=[ Similarly, it is illegal to specify a
632 nonconfirming type-related representation aspect for
633 an untagged by-reference type
634 after one or more types have been derived from it.],Old=[]}
635 @begin{Ramification}
636 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
637 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
638 On the other hand, subtype-specific representation
639 @Chg{Version=[3],New=[aspects],Old=[items]} may
640 be @Chg{Version=[3],New=[specified],Old=[given]}
641 for the first subtype of such a type@Chg{New=[, as can operational
642 @Chg{Version=[3],New=[aspects],Old=[items]}],Old=[]}.
643 @end{Ramification}
644 @begin{Reason}
645 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1],ARef=[AI05-0295-1]}
646 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0109-1]}
647 The reason for forbidding
648 @Chg{Version=[3],New=[specification of ],Old=[]}type-related
649 representation @Chg{Version=[3],New=[aspects],Old=[items]} on
650 untagged by-reference types is because a change of representation
651 is impossible when passing by reference (to an inherited
652 subprogram).@Chg{Version=[4],New=[ (A by-reference object cannot be copied
653 to change its representation.)],Old=[]}
654 The reason for forbidding
655 @Chg{Version=[3],New=[specification of ],Old=[]}type-related
656 representation @Chg{Version=[3],New=[aspects],Old=[items]} on
657 untagged types with user-defined primitive subprograms
658 was to prevent implicit change of representation for type-related
659 aspects of representation upon calling inherited subprograms,
660 because such changes of representation are likely to be
661 expensive at run time.
662 Changes of subtype-specific representation attributes, however, are
663 likely to be cheap.
664 This rule is not needed for tagged types,
665 because other rules prevent a type-related representation
666 @Chg{Version=[3],New=[aspect],Old=[item]}
667 from changing the representation of the parent part;
668 we want to allow
669 @Chg{Version=[3],New=[specifying ],Old=[]}a type-related
670 representation @Chg{Version=[3],New=[aspect],Old=[item]}
671 on a type extension to specify aspects of the extension part.
672 For example, @Chg{Version=[3],New=[specifying aspect],Old=[a @nt{pragma}]}
673 Pack will cause packing of the extension part, but not of the parent part.
674 @end{Reason}
675 @begin{Discussion}
676 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0109-1]}
677 @ChgAdded{Version=[4],Text=[@Ldquote@;By-reference type@rdquote usually
678 cannot be used in @LegalityTitle, as it is privacy breaking. Our use here
679 is privacy breaking, but we're stuck with it for compatibility reasons.
680 Since representation aspects cannot be specified on partial views, privacy
681 violations only can happen when a type includes a component of a private type.
682 In that case, whether these rules are triggered depends on the full type of
683 the private type @em which is clearly privacy breaking.]}
684 @end{Discussion}
685
686 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01],Ref=[8652/0011],ARef=[AI95-00117-01]}
687 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
688 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
689 @Chg{New=[Operational and representation],Old=[Representation]} aspects of
690 a generic formal parameter are the same as those of the actual.
691 @Chg{New=[Operational and representation aspects
692 @Chg{Version=[2],New=[],Old=[of a partial view ]}are the
693 same @Chg{Version=[2],New=[for all views of a type],Old=[as those of the full view]}.],Old=[]}
694 @Chg{Version=[3],New=[Specification of a],Old=[A]}
695 type-related representation @Chg{Version=[3],New=[aspect],Old=[item]}
696 is not allowed for a descendant of a generic formal untagged type.
697 @begin{Ramification}
698 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
699 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
700 @Chg{Version=[3],New=[Specifying representation aspects is],Old=[Representation
701 items are]} allowed for
702 types whose subcomponent types
703 or index subtypes are generic formal types.
704 @Chg{New=[@Chg{Version=[3],New=[Specifying operational
705 aspects],Old=[Operational items]} and subtype-related representation
706 @Chg{Version=[3],New=[aspects is],Old=[items are]}
707 allowed on descendants of generic formal types.],Old=[]}
708 @end{Ramification}
709 @begin{Reason}
710 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
711 Since it is not known whether a formal type has
712 user-defined primitive subprograms, specifying
713 type-related representation @Chg{Version=[3],New=[aspects],Old=[items]}
714 for them is not allowed, unless they are tagged (in which case only
715 the extension part is affected in any case).
716 @end{Reason}
717 @begin{Ramification}
718 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
719 @ChgAdded{Version=[2],Text=[All views of a type, including the incomplete
720 and partial views, have the same operational and representation aspects.
721 That's important so that the properties don't change when changing views.
722 While most aspects are not available for an incomplete view, we don't want
723 to leave any holes by not saying that they are the same.]}
724
725 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0083-1]}
726 @ChgAdded{Version=[3],Text=[However, this does not apply to objects.
727 Different views of an object can have
728 different representation aspects. For instance, an actual object passed
729 by reference and the associated formal parameter may have different values for
730 Alignment even though the formal parameter is merely a view of the
731 actual object. This is necessary to maintain the language design principle
732 that Alignments are always known at compile time.]}
733 @end{Ramification}
734
735 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
736 @Chg{Version=[3],New=[The specification of],Old=[A
737 representation item that specifies]} the Size@Chg{Version=[3],New=[ aspect],Old=[]}
738 for a given subtype, or the size or storage place for an object (including a component)
739 of a given subtype, shall allow for enough storage space to
740 accommodate any value of the subtype.
741
742 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
743 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
744 @Chg{Version=[3],New=[If a specification of a],Old=[A]}
745 representation @Chg{New=[or operational ],Old=[]}@Chg{Version=[3],New=[aspect],
746 Old=[item that]} is
747 not supported by the implementation@Chg{Version=[3],New=[, it ],Old=[]}is
748 illegal@Chg{Version=[3],New=[],Old=[,]} or raises an exception at run time.
749
750 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
751 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
752 @ChgAdded{Version=[2],Text=[A @nt{type_declaration} is illegal if it has one or
753 more progenitors, and a
754 @Chg{Version=[3],New=[nonconfirming value was specified
755 for a ],Old=[]}representation
756 @Chg{Version=[3],New=[aspect of],Old=[item applies to]}
757 an ancestor, and this@Chg{Version=[3],New=[],Old=[ representation item]}
758 conflicts with the representation of
759 some other ancestor. The cases that cause conflicts are
760 implementation defined.]}
761 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
762 Text=[The cases that cause conflicts between the representation of
763 the ancestors of a @nt{type_declaration}.]}]}
764 @begin{Reason}
765 @ChgRef{Version=[2],Kind=[AddedNormal]}
766 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
767 @ChgAdded{Version=[2],Type=[Leading],Text=[This rule is needed because it may be the case
768 that only the combination of types in a type declaration causes a conflict.
769 Thus it is not possible, in general, to reject the original representation
770 item@Chg{Version=[3],New=[ or @nt{aspect_specification}],Old=[]}.
771 For instance:]}
772 @begin{Example}
773 @ChgRef{Version=[2],Kind=[AddedNormal]}
774 @ChgAdded{Version=[2],Text=[@key{package} Pkg1 @key{is}
775 @key{type} Ifc @key{is interface};
776 @key{type} T @key{is tagged record}
777 Fld : Integer;
778 @key{end record};
779 @key{for} T @key{use record}
780 Fld @key{at} 0 @key{range} 0 .. Integer'Size - 1;
781 @key{end record};
782 @key{end} Pkg1;]}
783 @end{Example}
784 @ChgRef{Version=[2],Kind=[AddedNormal]}
785 @ChgAdded{Version=[2],Type=[Leading],Text=[Assume the implementation uses a
786 single tag with a default offset of zero, and that it allows the use of
787 nondefault locations for the tag (and thus accepts representation items
788 like the one above). The representation item will force a nondefault
789 location for the tag (by putting a component other than the tag into the
790 default location). Clearly, this package will be accepted by the
791 implementation. However, other declarations could cause trouble. For
792 instance, the implementation could reject:]}
793 @begin{Example}
794 @ChgRef{Version=[2],Kind=[AddedNormal]}
795 @ChgAdded{Version=[2],Text=[@key{with} Pkg1;
796 @key{package} Pkg2 @key{is}
797 @key{type} NewT @key{is new} Pkg1.T @key{and} Pkg1.Ifc @key{with null record};
798 @key{end} Pkg2;]}
799 @end{Example}
800 @ChgRef{Version=[2],Kind=[AddedNormal]}
801 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
802 @ChgAdded{Version=[2],Text=[because the declarations of T and Ifc have a
803 conflict in their representation items. This is clearly necessary (it's hard
804 to imagine how Ifc'Class could work with the tag at a location other than the
805 one it is expecting@Chg{Version=[3],New=[ without introducing distributed
806 overhead],Old=[]}).]}@Comment{Make Steve happy.}
807
808 @ChgRef{Version=[2],Kind=[AddedNormal]}
809 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
810 @ChgAdded{Version=[2],Text=[Conflicts will usually involve
811 implementation-defined attributes (for specifying the location of the tag,
812 for instance), although the example above shows that doesn't have to be the
813 case. For this reason, we didn't try to specify exactly what causes a
814 conflict; it will depend on the implementation's implementation model and
815 what representation @Chg{Version=[3],New=[aspects],Old=[items]} it
816 allows@Chg{Version=[3],New=[ to be changed],Old=[]}.]}
817 @end{Reason}
818 @begin{ImplNote}
819 @ChgRef{Version=[2],Kind=[AddedNormal]}
820 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
821 @ChgAdded{Version=[2],Text=[An implementation can only use this rule to
822 reject @nt{type_declaration}s where one of its ancestors
823 @Chg{Version=[3],New=[had a nonconfirming],Old=[has a]} representation
824 @Chg{Version=[3],New=[value specified],Old=[item]}.
825 An implementation must ensure that
826 the default representations of ancestors cannot conflict.]}
827 @end{ImplNote}
828 @end{Legality}
829
830 @begin{StaticSem}
831 If two subtypes statically match,
832 then their subtype-specific aspects (Size and Alignment)
833 are the same.
834 @PDefn2{Term=[statically matching],Sec=(effect on subtype-specific aspects)}
835 @begin{Reason}
836 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
837 This is necessary because we allow (for example)
838 conversion between access types whose designated subtypes
839 statically match.
840 Note that @Chg{Version=[3],New=[most aspects (including the subtype-specific aspects
841 Size and Alignment) may not be specified for a nonfirst subtype. The only
842 language-defined exceptions to this rule are the Static_Predicate and
843 Dynamic_Predicate aspects.],Old=[it is illegal to specify an aspect
844 (including a subtype-specific one) for a nonfirst subtype.]}
845
846 @Leading@Keepnext@;Consider, for example:
847 @begin{Example}
848 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114}
849 @key[package] P1 @key[is]
850 @key[subtype] S1 @key[is] Integer @key[range] 0..2**16-1;
851 @key[for] S1'Size @key[use] 16; --@RI{ Illegal!}
852 --@RI{ S1'Size would be 16 by default.}
853 @key[type] A1 @key[is] @key[access] @Chg{New=[@Key[all] ],Old=[]}S1;
854 X1: A1;
855 @key[end] P1;
856
857 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114}
858 @key[package] P2 @key[is]
859 @key[subtype] S2 @key[is] Integer @key[range] 0..2**16-1;
860 @key[for] S2'Size @key[use] 32; --@RI{ Illegal!}
861 @key[type] A2 @key[is] @key[access] @Chg{New=[@Key[all] ],Old=[]}S2;
862 X2: A2;
863 @key[end] P2;
864
865 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114}
866 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
867 @key[procedure] Q @key[is]
868 @key[use] P1, P2;
869 @key[type] Array1 @key[is] @key[array](Integer @key[range] <>) @key[of] @key[aliased] S1@Chg{Version=[3],New=[
870 @key[with] Pack],Old=[;
871 @key[pragma] Pack(Array1)]};
872 Obj1: Array1(1..100);
873 @key[type] Array2 @key[is] @key[array](Integer @key[range] <>) @key[of] @key[aliased] S2@Chg{Version=[3],New=[
874 @key[with] Pack],Old=[;
875 @key[pragma] Pack(Array2)]};
876 Obj2: Array2(1..100);
877 @key[begin]
878 X1 := Obj2(17)'@Chg{New=[Unchecked_],Old=[]}Access;
879 X2 := Obj1(17)'@Chg{New=[Unchecked_],Old=[]}Access;
880 @key[end] Q;
881 @end{Example}
882
883 Loads and stores through X1 would read and write 16 bits,
884 but X1 points to a 32-bit location.
885 Depending on the endianness of the machine,
886 loads might load the wrong 16 bits.
887 Stores would fail to zero the other half in any case.
888
889 Loads and stores through X2 would read and write 32 bits,
890 but X2 points to a 16-bit location.
891 Thus, adjacent memory locations would be trashed.
892
893 Hence, the above is illegal.
894 Furthermore, the compiler is forbidden from choosing different
895 Sizes by default, for the same reason.
896
897 The same issues apply to Alignment.
898
899 @end{Reason}
900
901 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]}
902 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1],ARef=[AI05-0295-1]}
903 A derived type inherits each type-related
904 @Chg{Version=[3],New=[representation ],Old=[]}aspect
905 @Chg{Version=[3],New=[],Old=[@Chg{New=[of representation ],Old=[]}]}of
906 its parent type that
907 was directly specified before the declaration of the derived type,
908 or (in the case where the parent is derived)
909 that was inherited by the parent type from the grandparent type.
910 A derived subtype inherits each subtype-specific
911 @Chg{Version=[3],New=[representation ],Old=[]}aspect
912 @Chg{Version=[3],New=[],Old=[@Chg{New=[of representation ],Old=[]}]}of
913 its parent subtype that
914 was directly specified before the declaration of the derived type,
915 or (in the case where the parent is derived)
916 that was inherited by the parent subtype from the grandparent subtype,
917 but only if the parent subtype statically matches the first subtype of
918 the parent type.
919 An inherited @Chg{Version=[3],New=[representation ],Old=[]}aspect
920 @Chg{Version=[3],New=[],Old=[of representation ]}is
921 overridden by a subsequent
922 @Chg{Version=[3],New=[@nt{aspect_specification} or ],Old=[]}representation
923 item that specifies @Chg{Version=[3],New=[a different value for ],Old=[]}the
924 same aspect of the type or subtype.
925 @begin{Honest}
926 A @nt{record_representation_clause} for a record extension
927 does not override the layout of the parent part;
928 if the layout was specified for the parent type,
929 it is inherited by the record extension.
930 @end{Honest}
931 @begin{Ramification}
932 If a representation item for the parent appears after the
933 @nt{derived_@!type_@!definition},
934 then inheritance does not happen for that representation item.
935
936 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0295-1]}
937 @ChgAdded{Version=[3],Text=[If an inherited aspect is confirmed by
938 an @nt{aspect_specification} or a later representation item for a derived type,
939 the confirming specification does
940 not override the inherited one. Thus the derived type has both a specified
941 confirming value and an inherited nonconfirming representation value @em this
942 means that rules that apply only to nonconfirming representation values still
943 apply to this type.]}
944
945 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0109-1]}
946 @ChgAdded{Version=[4],Text=[If an aspect was specified by an
947 @nt{aspect_specification} and the parent type has not yet been frozen, then
948 the inherited aspect might not yet have been resolved and evaluated. The
949 implementation will need to have a mechanism to handle such an aspect.]}
950 @end{Ramification}
951
952 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
953 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]}
954 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1],ARef=[AI05-0295-1]}
955 @ChgAdded{Version=[1],Text=[In contrast, whether operational aspects are
956 inherited by @Chg{Version=[3],New=[a],Old=[@Chg{Version=[2],New=[an untagged],Old=[a]}]}
957 derived type depends on each specific aspect@Chg{Version=[3],New=[; unless specified,
958 an operational aspect is not inherited],Old=[]}. @Chg{Version=[3],New=[],
959 Old=[@Chg{Version=[2],New=[@Redundant[Operational aspects are never inherited
960 for a tagged type.] ],Old=[]}]}When operational aspects are
961 inherited by @Chg{Version=[3],New=[a],Old=[@Chg{Version=[2],New=[an untagged],Old=[a]}]} derived type,
962 aspects that were directly specified @Chg{Version=[2],New=[by
963 @Chg{Version=[3],New=[@nt{aspect_specification}s or ],Old=[]}operational
964 items that are visible at the point],Old=[before the declaration]} of
965 the derived type@Chg{Version=[2],New=[ declaration],Old=[]}, or
966 (in the case where the parent is derived)
967 that were inherited by the parent type from the grandparent type are inherited.
968 An inherited operational aspect is overridden by a subsequent
969 @Chg{Version=[3],New=[@nt{aspect_specification} or ],Old=[]}operational
970 item that specifies the same aspect of the type.]}
971 @begin{Ramification}
972 @ChgRef{Version=[1],Kind=[Added]}
973 @ChgAdded{Version=[1],Text=[As with representation items, if an operational
974 item for the parent appears after the @nt{derived_@!type_@!definition}, then
975 inheritance does not happen for that operational item.]}
976 @end{Ramification}
977 @begin{Discussion}
978 @ChgRef{Version=[1],Kind=[Added]}
979 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]}
980 @ChgRef{Version=[3],Kind=[DeletedAddedNoDelMsg],ARef=[AI05-0183-1]}
981 @ChgDeleted{Version=[3],Text=[@Chg{Version=[1],New=[@Chg{Version=[2],New=[Only],Old=[Currently, only]}
982 untagged types inherit operational aspects.
983 @Chg{Version=[2],New=[Inheritance from tagged types causes problems, as the
984 different views can have different visibility on operational items @em
985 potentially leading to operational items that depend on the view. We want
986 aspects to be the same for all views. Untagged types don't have this problem
987 as plain private types don't have ancestors, and thus can't inherit anything.
988 In addition, it seems unlikely that we'll need inheritance for tagged types,
989 as usually we'll want to incorporate the parent's operation into a new one that
990 also handles any extension components.],Old=[We considered writing this rule
991 that way, but rejected it as that could be too
992 specific for future operational aspects. (After all, that is precisely the
993 problem that caused us to introduce @lquotes@;operational aspects@rquotes in
994 the first place.)]}],Old=[]}]}
995 @end{Discussion}
996
997 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]}
998 @ChgAdded{Version=[2],Text=[When an aspect that is a subprogram is inherited,
999 the derived type inherits the aspect in the same way that a derived type
1000 inherits a user-defined primitive subprogram from its parent (see
1001 @RefSecNum{Derived Types and Classes}).]}
1002 @begin{Reason}
1003 @ChgRef{Version=[2],Kind=[AddedNormal]}
1004 @ChgAdded{Version=[2],Text=[This defines the parameter names and types,
1005 and the needed implicit conversions.]}
1006 @end{Reason}
1007
1008 @Leading@;Each aspect of representation of an entity is as follows:
1009 @begin{Itemize}
1010 @Defn2{Term=[specified],
1011 Sec=(of an aspect of representation of an entity)}
1012 If the aspect is @i{specified} for the entity,
1013 meaning that it is
1014 either directly specified or inherited,
1015 then that aspect of the entity is as specified,
1016 except in the case of Storage_Size,
1017 which specifies a minimum.
1018 @begin{Ramification}
1019 This rule implies that queries of the aspect return the
1020 specified value. For example, if the user writes @lquotes@;@key{for}
1021 X'Size @key{use} 32;@rquotes@;,
1022 then a query of X'Size will return 32.
1023 @end{Ramification}
1024
1025 @PDefn{unspecified}
1026 If an aspect of representation of an entity is not specified,
1027 it is chosen by default in an unspecified manner.
1028 @end{Itemize}
1029 @begin{Ramification}
1030 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1031 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1032 Note that @Chg{New=[@Chg{Version=[3],New=[specifying a ],Old=[]}representation
1033 @Chg{Version=[3],New=[aspect],Old=[items]}],Old=[@nt{representation_clause}s]}
1034 can affect the semantics of the entity.
1035
1036 The rules forbid things like
1037 @lquotes@;@key[for] S'Base'Alignment @key[use] ...@rquotes@;
1038 and
1039 @lquotes@;@key[for] S'Base @key[use] record ...@rquotes@;.
1040 @end{Ramification}
1041 @begin{Discussion}
1042 The intent is that implementations will represent the
1043 components of a composite value in the same way for all subtypes of a
1044 given composite type.
1045 Hence, Component_Size and record layout are type-related aspects.
1046 @end{Discussion}
1047 @begin{Ramification}
1048 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0083-1]}
1049 @ChgAdded{Version=[3],Text=[As noted previously, in the case of an
1050 object, the entity mentioned in this text is a specific view of an object. That
1051 means that only references to the same view of an object that has a specified
1052 value for a representation aspect @i<R> necessarily have that value for the
1053 aspect @i<R>. The value of the aspect @i<R> for a different view of that object
1054 is unspecified. In particular, this means that the representation values for
1055 by-reference parameters is unspecified; they do not have to be the same as those
1056 of the underlying object.]}
1057 @end{Ramification}
1058
1059 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
1060 @ChgAdded{Version=[1],Text=[@Defn2{Term=[specified], Sec=(of an operational aspect of an entity)}
1061 If an operational aspect is @i<specified> for an entity (meaning
1062 that it is either directly specified or inherited), then that aspect of the
1063 entity is as specified. Otherwise, the aspect of the entity has the default
1064 value for that aspect.]}
1065
1066 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
1067 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
1068 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[An @nt{aspect_specification}
1069 or ],Old=[A]}representation
1070 item that specifies @Chg{Version=[3],New=[a],Old=[an aspect of]}
1071 representation@Chg{Version=[3],New=[ aspect],Old=[]}
1072 that would have been chosen in the absence of the
1073 @Chg{Version=[3],New=[@nt{aspect_specification} or ],Old=[]}
1074 representation item is said to be
1075 @i{confirming}.@Defn2{Term=[confirming], Sec=(representation item)}@Chg{Version=[3],New=[
1076 The aspect value specified in this case is said to be a
1077 @i<confirming> representation aspect value. Other values of the aspect
1078 are said to be @i<nonconfirming>, as are the
1079 @nt{aspect_specification}s and representation items that specified
1080 them.@Defn2{Term=[confirming], Sec=(representation value)}
1081 @Defn2{Term=[confirming], Sec=(aspect specification)}
1082 @Defn2{Term=[nonconfirming], Sec=(representation value)}
1083 @Defn2{Term=[nonconfirming], Sec=(representation item)}
1084 @Defn2{Term=[nonconfirming], Sec=(aspect specification)}],Old=[]}]}
1085 @end{StaticSem}
1086
1087 @begin{RunTime}
1088 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1089 @Chg{New=[@PDefn2{Term=[elaboration], Sec=(aspect_clause)}],
1090 Old=[@PDefn2{Term=[elaboration], Sec=(representation_clause)}]}
1091 For the elaboration of @Chg{New=[an @nt{aspect_clause}],
1092 Old=[a @nt{representation_clause}]},
1093 any evaluable constructs within it are evaluated.
1094 @begin{Ramification}
1095 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1096 Elaboration of representation pragmas is covered by the
1097 general rules for pragmas in @Chg{Version=[3],New=[@RefSecNum{Pragmas}],Old=[Section 2]}.
1098 @end{Ramification}
1099 @end{RunTime}
1100
1101 @begin{ImplPerm}
1102 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1103 An implementation may interpret
1104 @Chg{Version=[3],New=[],Old=[aspects of
1105 ]}representation@Chg{Version=[3],New=[ aspects],Old=[]}
1106 in an implementation-defined manner.
1107 An implementation may place implementation-defined restrictions on
1108 @Chg{Version=[3],New=[the specification of ],Old=[]}representation
1109 @Chg{Version=[3],New=[aspects],Old=[items]}.
1110 @RootDefn{recommended level of support}
1111 A @i{recommended level of support} is
1112 @Chg{Version=[3],New=[defined],Old=[specified]} for
1113 @Chg{Version=[3],New=[the specification of ],Old=[]}representation
1114 @Chg{Version=[3],New=[aspects],Old=[items]}
1115 and related features in each subclause.
1116 These recommendations are changed to requirements
1117 for implementations that support the Systems Programming Annex
1118 (see @RefSec{Required Representation Support}).
1119
1120 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[0],Text=[The
1121 interpretation of each @Chg{Version=[3],New=[],Old=[aspect of
1122 ]}representation@Chg{Version=[3],New=[ aspect],Old=[]}.]}
1123
1124 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[0],Text=[Any restrictions
1125 placed upon @Chg{Version=[3],New=[the specification of ],Old=[]}representation
1126 @Chg{Version=[3],New=[aspects],Old=[items]}.]}
1127
1128 @begin{Ramification}
1129 Implementation-defined restrictions may be enforced either at compile
1130 time or at run time.
1131 There is no requirement that an implementation justify any such
1132 restrictions.
1133 They can be based on avoiding implementation complexity,
1134 or on avoiding excessive inefficiency, for example.
1135
1136 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
1137 @ChgAdded{Version=[1],Text=[There is no such permission for operational aspects.]}
1138 @end{Ramification}
1139 @end{ImplPerm}
1140
1141 @begin{ImplAdvice}
1142 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1143 @PDefn2{Term=[recommended level of support], Sec=(with respect to
1144 nonstatic expressions)}
1145 The recommended level of support for
1146 @Chg{Version=[3],New=[the specification of ],Old=[]}all representation
1147 @Chg{Version=[3],New=[aspects],Old=[items]}
1148 is qualified as follows:
1149 @begin{Itemize}
1150 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
1151 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
1152 @ChgAdded{Version=[2],Text=[A confirming
1153 @Chg{Version=[3],New=[specification for a ],Old=[]}representation
1154 @Chg{Version=[3],New=[aspect],Old=[item]}
1155 should be supported.]}
1156 @begin{Honest}
1157 @ChgRef{Version=[2],Kind=[AddedNormal]}
1158 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1159 @ChgAdded{Version=[2],Text=[A confirming representation
1160 @Chg{Version=[3],New=[aspect value],Old=[item]} might not be possible for some
1161 entities. For instance, consider an unconstrained array. The size of such a
1162 type is implementation-defined, and might not actually be a representable
1163 value, or might not be static.]}
1164 @end{Honest}
1165
1166 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1167 An implementation need not support @Chg{Version=[3],New=[the specification for
1168 a ],Old=[]}representation
1169 @Chg{Version=[3],New=[aspect that contains],Old=[items containing]}
1170 nonstatic expressions,
1171 @Chg{Version=[3],New=[unless],Old=[except that an implementation should
1172 support a representation item for a given entity if]} each nonstatic
1173 expression@Chg{Version=[3],New=[],Old=[ in the representation item]}
1174 is a @Chg{Version=[3],New=[@nt{name}],Old=[name]} that statically denotes
1175 a constant declared before the entity.
1176 @begin{Reason}
1177 @Leading@;This is to avoid the following sort of thing:
1178 @begin{Example}
1179 X : Integer := F(...);
1180 Y : Address := G(...);
1181 @key[for] X'Address @key[use] Y;
1182 @end{Example}
1183
1184 In the above, we have to evaluate the initialization expression for X
1185 before we know where to put the result.
1186 This seems like an unreasonable implementation burden.
1187
1188 @Leading@;The above code should instead be written like this:
1189 @begin{Example}
1190 Y : @key[constant] Address := G(...);
1191 X : Integer := F(...);
1192 @key[for] X'Address @key[use] Y;
1193 @end{Example}
1194
1195 This allows the expression @lquotes@;Y@rquotes@; to be safely evaluated before X is
1196 created.
1197
1198 The constant could be a formal parameter of mode @key[in].
1199
1200 An implementation can support other nonstatic expressions if it wants
1201 to. Expressions of type Address are hardly ever static,
1202 but their value might be known at compile time anyway
1203 in many cases.
1204 @end{Reason}
1205
1206 An implementation need not support a specification for the
1207 Size for a given composite subtype, nor the size or storage place for an object
1208 (including a component) of a given composite subtype, unless the constraints
1209 on the subtype and its composite subcomponents (if any)
1210 are all static constraints.
1211
1212
1213 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
1214 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1215 @Chg{Version=[2],New=[An implementation need not support
1216 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1217 representation @Chg{Version=[3],New=[aspect value],Old=[item]}
1218 if it could cause an aliased object or an object of a
1219 by-reference type to be allocated at a nonaddressable location or, when the
1220 alignment attribute of the subtype of such an object is nonzero, at an address
1221 that is not an integral multiple of that alignment.],Old=[An aliased component,
1222 or a component whose type is by-reference, should always be allocated at an
1223 addressable location.]}
1224 @begin{Reason}
1225 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-0079}
1226 The intent is that access types, type System.Address,
1227 and the pointer used for a by-reference parameter should
1228 be implementable as a single machine address @em bit-field pointers
1229 should not be required.
1230 (There is no requirement that this implementation be used @em we just
1231 want to make sure @Chg{New=[it's],Old=[its]} feasible.)
1232 @end{Reason}
1233 @begin{ImplNote}
1234 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
1235 @Chg{Version=[2],New=[We want subprograms to be able to assume the properties
1236 of the types of their parameters inside of subprograms. While many objects
1237 can be copied to allow this
1238 (and thus do not need limitations), aliased or by-reference objects cannot
1239 be copied (their memory location is part of their identity). Thus,],
1240 Old=[Note that]}
1241 the above rule does not apply to types that merely allow
1242 by-reference parameter passing;
1243 for such types, a copy typically needs to be made at the call site
1244 when a bit-aligned component is passed as a parameter.
1245 @end{ImplNote}
1246
1247 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1248 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1249 @ChgAdded{Version=[2],Text=[An implementation need not support
1250 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1251 representation @Chg{Version=[3],New=[aspect value],Old=[item]}
1252 if it could cause an aliased object of an elementary type
1253 to have a size other than that which would have been chosen by default.]}
1254 @begin{Reason}
1255 @ChgRef{Version=[2],Kind=[AddedNormal]}
1256 @ChgAdded{Version=[2],Text=[Since all bits of elementary objects participate
1257 in operations, aliased objects must not have a different size than that
1258 assumed by users of the access type.]}
1259 @end{Reason}
1260
1261 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1262 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1263 @ChgAdded{Version=[2],Text=[An implementation need not support
1264 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1265 representation @Chg{Version=[3],New=[aspect value],Old=[item]}
1266 if it could cause an aliased object of a composite type, or
1267 an object whose type is by-reference, to have a size smaller than that which
1268 would have been chosen by default.]}
1269 @begin{Reason}
1270 @ChgRef{Version=[2],Kind=[AddedNormal]}
1271 @ChgAdded{Version=[2],Text=[Unlike elementary objects, there is no
1272 requirement that all bits of a composite object participate in operations.
1273 Thus, as long as the object is the same or larger in size than that expected
1274 by the access type, all is well.]}
1275 @end{Reason}
1276 @begin{Ramification}
1277 @ChgRef{Version=[2],Kind=[AddedNormal]}
1278 @ChgAdded{Version=[2],Text=[This rule presumes that the implementation
1279 allocates an object of a size specified to be larger than the default size in
1280 such a way that access of the default size suffices to correctly read and
1281 write the value of the object.]}
1282 @end{Ramification}
1283
1284 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1285 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1286 @ChgAdded{Version=[2],Text=[An implementation need not support
1287 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1288 subtype-specific representation @Chg{Version=[3],New=[aspect value
1289 for],Old=[item specifying an aspect of representation of]}
1290 an indefinite or abstract subtype.]}
1291 @begin{Reason}
1292 @ChgRef{Version=[2],Kind=[AddedNormal]}
1293 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1294 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Representation aspects],
1295 Old=[Aspects of representations]} are often not
1296 well-defined for such types.]}
1297 @end{Reason}
1298
1299 @begin{Ramification}
1300 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00075}
1301 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
1302 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1303 @Chg{Version=[3],New=[A type with the Pack aspect specified],Old=[A pragma Pack]}
1304 will typically not @Chg{Version=[3],New=[be packed],Old=[pack]} so tightly as to
1305 disobey the above
1306 @Chg{Version=[2],New=[rules],Old=[rule]}. A Component_Size clause or
1307 @nt{record_representation_clause} will typically @Chg{New=[be],Old=[by]}
1308 illegal if it disobeys the above @Chg{Version=[2],New=[rules],Old=[rule]}.
1309 Atomic components have similar restrictions
1310 (see @RefSec{Shared Variable Control}).
1311 @end{Ramification}
1312 @end{Itemize}
1313
1314 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1315 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1316 @ChgAdded{Version=[2],Text=[For purposes of these rules, the determination of
1317 whether @Chg{Version=[3],New=[specifying ],Old=[]}a
1318 representation @Chg{Version=[3],New=[aspect value for],Old=[item applied to]}
1319 a type @i{could cause} an object to have
1320 some property is based solely on the properties of the type itself, not on any
1321 available information about how the type is used. In particular, it presumes
1322 that minimally aligned objects of this type might be declared at some point.]}
1323 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1324 Text=[The recommended level of support for all representation items should be
1325 followed.]}]}
1326 @end{ImplAdvice}
1327
1328 @begin{Notes}
1329 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1330 @ChgAdded{Version=[3],Text=[Aspects that can be specified are defined
1331 throughout this International Standard, and are summarized in
1332 @RefSecNum{Language-Defined Aspects}.]}
1333 @end{Notes}
1334
1335
1336 @begin{Incompatible83}
1337 @Defn{incompatibilities with Ada 83}
1338 It is now illegal for a representation item to cause a derived
1339 by-reference type to have a different record layout from its
1340 parent.
1341 This is necessary for by-reference parameter passing to be feasible.
1342 This only affects programs that specify the representation of types
1343 derived from types containing tasks;
1344 most by-reference types are new to Ada 95.
1345 For example, if A1 is an array of tasks, and A2 is derived from A1,
1346 it is illegal to apply a @nt{pragma} Pack to A2.
1347 @end{Incompatible83}
1348
1349 @begin{Extend83}
1350 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1351 @Defn{extensions to Ada 83}
1352 Ada 95 allows additional @Chg{New=[@nt{aspect_clause}s],
1353 Old=[@nt{representation_clause}s]} for objects.
1354 @end{Extend83}
1355
1356 @begin{DiffWord83}
1357 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1358 The syntax rule for @ntf{type_representation_clause} is removed;
1359 the right-hand side of that rule is moved up to where it was used,
1360 in @Chg{New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]}.
1361 There are two references to @lquotes@;type representation clause@rquotes@; in RM83,
1362 both in Section 13; these have been reworded.
1363 @Chg{New=[Also, the @ntf{representation_clause} has been renamed the
1364 @nt{aspect_clause} to reflect that it can be used to control more than just
1365 representation aspects.],Old=[]}
1366
1367 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1368 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1369 We have defined a new term @lquotes@;representation item,@rquotes@;
1370 which includes @Chg{New=[all representation clauses],
1371 Old=[@nt{representation_clause}s]} and representation pragmas, as well as
1372 @nt<component_clause>s.
1373 This is convenient because the rules are almost identical for all @Chg{New=[of them],
1374 Old=[three]}. @Chg{New=[We have also defined the new terms
1375 @lquotes@;operational item@rquotes@; and @lquotes@;operational aspects@rquotes@;
1376 in order to conveniently handle new types of @Chg{Version=[2],New=[specifiable],Old=[specifable]} entities.],Old=[]}
1377
1378 All of the forcing occurrence stuff has been moved into its own
1379 subclause (see @RefSecNum{Freezing Rules}),
1380 and rewritten to use the term @lquotes@;freezing@rquotes@;.
1381
1382 RM83-13.1(10) requires implementation-defined restrictions on
1383 representation items to be enforced at compile time.
1384 However, that is impossible in some cases.
1385 If the user specifies a junk (nonstatic) address in an address
1386 clause, and the implementation chooses to detect the error (for example,
1387 using hardware memory management with protected pages), then it's
1388 clearly going to be a run-time error.
1389 It seems silly to call that @lquotes@;semantics@rquotes@; rather than
1390 @lquotes@;a restriction.@rquotes@;
1391
1392 RM83-13.1(10) tries to pretend that @ntf{representation_clause}s don't affect
1393 the semantics of the program.
1394 One counter-example is the Small clause.
1395 Ada 95 has more counter-examples.
1396 We have noted the opposite above.
1397
1398 Some of the more stringent requirements are moved to
1399 @RefSec{Required Representation Support}.
1400 @end{DiffWord83}
1401
1402 @begin{Extend95}
1403 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1404 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1405 @b[Amendment Correction:] Confirming representation items are
1406 defined, and the recommended level of support is now that they always
1407 be supported.]}
1408 @end{Extend95}
1409
1410 @begin{DiffWord95}
1411 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
1412 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added operational items
1413 in order to eliminate unnecessary restrictions and permissions on
1414 stream attributes. As part of this, @ntf{representation_clause} was
1415 renamed to @nt{aspect_clause}.]}
1416
1417 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01],ARef=[AI95-00326-01]}
1418 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to say that the
1419 partial and full views have the same operational and representation aspects.
1420 Ada 2005 extends this to cover all views, including the incomplete view.]}
1421
1422 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]}
1423 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed operational items
1424 to have inheritance specified for each such aspect.]}
1425
1426 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1427 @ChgAdded{Version=[2],Text=[Added wording to allow the rejection of
1428 types with progenitors that have conflicting representation items.]}
1429
1430 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1431 @ChgAdded{Version=[2],Text=[The description of the representation of an
1432 object was clarified (with great difficulty reaching agreement). Added
1433 wording to say that representation items on aliased and by-reference objects
1434 never need be supported if they would not be implementable without
1435 distributed overhead even if other recommended level of support says
1436 otherwise. This wording matches the rules with reality.]}
1437
1438 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00444-01]}
1439 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
1440 @ChgAdded{Version=[2],Text=[Added wording so that inheritance depends on
1441 whether operational items are visible rather than whether they occur before
1442 the declaration (we don't want to look into private parts).
1443 @Chg{Version=[3],New=[Also limited],Old=[Limited]}
1444 operational inheritance to untagged types to avoid
1445 @Chg{Version=[3],New=[anomalies],Old=[anomolies]} with private extensions
1446 (this is not incompatible, no existing operational attribute used this
1447 capability). Also added wording to clearly define that subprogram inheritance
1448 works like derivation of subprograms.]}
1449 @end{DiffWord95}
1450
1451 @begin{Incompatible2005}
1452 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0106-1]}
1453 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
1454 Specifying a language-defined aspect for a generic formal parameter is no
1455 longer allowed. Most aspects could not be specified on these anyway; moreover,
1456 this was not allowed in Ada 83, so it is unlikely that compilers are
1457 supporting this as a capability (and it is not likely that they have a
1458 consistent definition of what it means if it is allowed). Thus, we expect
1459 this to occur rarely in existing programs.]}
1460 @end{Incompatible2005}
1461
1462 @begin{DiffWord2005}
1463 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1]}
1464 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined that overriding of
1465 an representation aspect only happens for a nonconfirming representation
1466 item. This prevents a derived type from being considered to have
1467 only a confirming representation item when the value would be nonconfirming
1468 if given on a type that does not inherit any aspects of representation.
1469 This change just eliminates a wording confusion and ought not change any
1470 behavior.]}
1471
1472 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0112-1]}
1473 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined a default naming for
1474 representation aspects that are representation pragmas.]}
1475
1476 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1477 @ChgAdded{Version=[3],Text=[Added text ensuring that the rules for
1478 representational and operational items also apply appropriately to
1479 @nt{aspect_specification}s; generalized operational aspects so that they
1480 can be defined for entities other than types. Any extensions are documented
1481 elsewhere.]}
1482
1483 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0295-1]}
1484 @ChgAdded{Version=[3],Text=[Rewrote many rules to be in terms of
1485 "specifying a representation aspect" rather than use of
1486 a "representation item". This better separates @i<how> an aspect is
1487 specified from @i<what> rules apply to the value of the aspect.]}
1488 @end{DiffWord2005}
1489
1490 @begin{Incompatible2012}
1491 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0109-1]}
1492 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
1493 Added a rule that makes it illegal to specify a representation value after
1494 a type is derived from an untagged by-reference type. This restriction is
1495 incompatible, but since the implementation would have had to copy an object
1496 that does not allow copying in order to change the representation for any
1497 implicit or explicit conversion between the original and the derived type,
1498 it is unlikely that any program could exist without running into internal
1499 compiler errors or bogus results.]}
1500 @end{Incompatible2012}
1501
1502 @begin{DiffWord2012}
1503 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0116-1]}
1504 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that an aspect
1505 (any aspect) can be specified only once for an entity, no matter what
1506 means of specifying it are used. We did not document this as an
1507 incompatibility as only aspects that are neither operational nor
1508 representation could change behavior and there is no known implementation
1509 of these new aspects that allows multiple definitions.]}
1510 @end{DiffWord2012}
1511
1512
1513 @LabeledAddedSubClause{Version=[3],Name=[Aspect Specifications]}
1514
1515 @begin{Intro}
1516 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1517 @ChgAdded{Version=[3],Text=[@Redundant[Certain representation or operational
1518 aspects of an entity may be specified as part of its declaration using an
1519 @nt{aspect_specification}, rather than using a separate representation or
1520 operational item.] The declaration with the @nt{aspect_specification} is termed
1521 the @i{associated declaration}.@Defn2{Term=[associated declaration],Sec=[of an
1522 aspect specification]}]}
1523 @end{Intro}
1524
1525 @begin{Syntax}
1526 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1527 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<aspect_specification>,Old=<>}>,
1528 rhs=`@Chg{Version=[3],New="
1529 @key[with] @Syn2{aspect_mark} [=> @Syn2{aspect_definition}] {,
1530 @Syn2{aspect_mark} [=> @Syn2{aspect_definition}] }",Old=<>}'}
1531
1532 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1533 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<aspect_mark>,Old=<>}>,
1534 rhs="@Chg{Version=[3],New=<@SynI<aspect_>@Syn2<identifier>['Class]>,Old=<>}"}
1535
1536 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1537 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<aspect_definition>,Old=<>}>,
1538 rhs="@Chg{Version=[3],New=<@Syn2<name> | @Syn2<expression> | @Syn2<identifier>>,Old=<>}"}
1539
1540 @end{Syntax}
1541
1542 @begin{Metarules}
1543 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1544 @ChgAdded{Version=[3],Text=[The @nt{aspect_specification} is an
1545 optional element in most kinds of declarations. Here is a list
1546 of all kinds of declarations and an indication
1547 of whether or not they allow aspect clauses, and in some cases
1548 a short discussion of why (* = allowed, NO = not allowed). Kinds
1549 of declarations with no indication are followed by their subdivisions
1550 (which have indications).]}
1551
1552 @begin{Display}
1553 @ChgRef{Version=[3],Kind=[AddedNormal]}
1554 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
1555 @ChgAdded{Version=[3],Text=[@nt{basic_declaration}
1556 @nt{type_declaration}
1557 @nt{full_type_declaration}
1558 @i<type declaration syntax>*
1559 @nt{task_type_declaration}*
1560 @nt{protected_type_declaration}*
1561 @nt{incomplete_type_declaration} -- NO
1562 -- @Examcom{Incomplete type aspects cannot be read by an attribute or specified by @nt{attribute_definition_clause}s }
1563 -- @Examcom{(the attribute name is illegal), so it would not make sense to allow this in another way.}
1564 @nt{private_type_declaration}*
1565 @nt{private_extension_declaration}*
1566 @nt{subtype_declaration}*
1567 @nt{object_declaration}
1568 @i<object declaration syntax>*
1569 @nt{single_task_declaration}*
1570 @nt{single_protected_declaration}*
1571 @nt{number_declaration} -- NO
1572 @nt{subprogram_declaration}*
1573 @nt{abstract_subprogram_declaration}*
1574 @nt{null_procedure_declaration}*@Chg{Version=[4],New=[
1575 @nt{expression_function_declaration}*],Old=[]}
1576 @nt{package_declaration}* -- @Examcom{via} @nt{package_specification}
1577 @nt{renaming_declaration}*
1578 -- @Examcom{There are no language-defined aspects that may be specified}
1579 -- @Examcom{on renames, but implementations might support some.}
1580 @nt{exception_declaration}*
1581 @nt{generic_declaration}
1582 @nt{generic_subprogram_declaration}*
1583 @nt{generic_package_declaration}* -- @Examcom{via} @nt{package_specification}
1584 @nt{generic_instantiation}*
1585 @nt{enumeration_literal_specification} -- NO
1586 @nt{discriminant_specification} -- NO
1587 @nt{component_declaration}*
1588 @nt{loop_parameter_specification} -- NO
1589 @nt{iterator_specification} -- NO
1590 @nt{parameter_specification} -- NO
1591 @nt{subprogram_body}* -- @Examcom{ - but language-defined aspects only if there is no explicit specification}
1592 @nt{entry_declaration}*
1593 @nt{entry_index_specification} -- NO
1594 @nt{subprogram_body_stub}* -- @Examcom{ - but language-defined aspects only if there is no explicit specification}
1595 @nt{choice_parameter_specification} -- NO
1596 @nt{generic_formal_parameter_declaration}
1597 -- @Examcom{There are no language-defined aspects that may be specified}
1598 -- @Examcom{on generic formals, but implementations might support some.}
1599 @nt{formal_object_declaration}*
1600 @nt{formal_type_declaration}*
1601 @nt{formal_subprogram_declaration}
1602 @nt{formal_concrete_subprogram_declaration}*
1603 @nt{formal_abstract_subprogram_declaration}*
1604 @nt{formal_package_declaration}*
1605 @nt{extended_return_statement} -- NO]}
1606
1607 @ChgRef{Version=[3],Kind=[AddedNormal]}
1608 @ChgAdded{Version=[3],Text=[-- @Examcom{We also allow @nt{aspect_specification}s on all kinds of bodies, but are no language-defined aspects}
1609 -- @Examcom{that may be specified on a body. These are allowed for implementation-defined aspects.}
1610 -- @Examcom{See above for subprogram bodies and stubs (as these can be declarations).}
1611 @nt{package_body}*
1612 @nt{task_body}*
1613 @nt{protected_body}*
1614 @nt{package_body_stub}*
1615 @nt{task_body_stub}*
1616 @nt{protected_body_stub}*]}
1617 @end{Display}
1618
1619 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0267-1]}
1620 @ChgAdded{Version=[3],Text=[Syntactically, @nt{aspect_specification}s
1621 generally are located at the end of declarations. When a declaration is all in
1622 one piece such as a @nt{null_procedure_declaration}, @nt{object_declaration},
1623 or @nt{generic_instantiation} the @nt{aspect_specification} goes at the end of
1624 the declaration; it is then more visible and less likely to interfere with the
1625 layout of the rest of the structure. However, we make an exception for program
1626 units (other than subprogram specifications) and bodies, in which the
1627 @nt{aspect_specification} goes before the @key[is]. In these cases, the entity
1628 could be large and could contain other declarations that also have
1629 @nt{aspect_specification}s, so it is better to put the
1630 @nt{aspect_specification} toward the top of the declaration. (Some aspects @en
1631 such as Pure @en also affect the legality of the contents of a unit, so it
1632 would be annoying to only see those after reading the entire unit.)]}
1633
1634 @end{Metarules}
1635
1636 @begin{Resolution}
1637
1638 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1639 @ChgAdded{Version=[3],Type=[Leading],Text=[An @nt{aspect_mark} identifies an
1640 aspect of the entity defined by the associated declaration (the @i<associated
1641 entity>@Defn2{Term=[associated entity],Sec=[of an aspect specification]}); the
1642 aspect denotes an object, a value, an expression, a subprogram, or some other
1643 kind of entity. If the @nt{aspect_mark} identifies:]}
1644 @begin{Itemize}
1645
1646 @ChgRef{Version=[3],Kind=[AddedNormal]}
1647 @ChgAdded{Version=[3],Text=[an aspect that denotes an
1648 object, the @nt{aspect_definition} shall be a @nt{name}. The expected type for
1649 the @nt{name} is the type of the identified aspect of the associated
1650 entity;@PDefn2{Term=[expected type], Sec=[object in an @nt{aspect_specification}]}]}
1651
1652 @ChgRef{Version=[3],Kind=[AddedNormal]}
1653 @ChgAdded{Version=[3],Text=[an aspect that is
1654 a value or an expression, the @nt{aspect_definition} shall be an @nt{expression}.
1655 The expected type for the @nt{expression} is the type of the identified aspect
1656 of the associated
1657 entity;@PDefn2{Term=[expected type],
1658 Sec=[@nt{name} in an @nt{aspect_specification}]}@PDefn2{Term=[expected type],
1659 Sec=[@nt{expression} in an @nt{aspect_specification}]}]}
1660
1661 @ChgRef{Version=[3],Kind=[AddedNormal]}
1662 @ChgAdded{Version=[3],Text=[an aspect that denotes a subprogram, the
1663 @nt{aspect_definition} shall be a @nt{name}; the expected profile for the @nt{name}
1664 is the profile required for the aspect of the associated
1665 entity;@PDefn2{Term=[expected profile], Sec=[@nt{name} in an @nt{aspect_specification}]}]}
1666
1667 @ChgRef{Version=[3],Kind=[AddedNormal]}
1668 @ChgAdded{Version=[3],Text=[an aspect that
1669 denotes some other kind of entity, the @nt{aspect_definition} shall be a
1670 @nt{name}, and the name shall resolve to denote an entity of the appropriate
1671 kind;]}
1672
1673 @ChgRef{Version=[3],Kind=[AddedNormal]}
1674 @ChgAdded{Version=[3],Text=[an aspect that is given by an identifier specific to
1675 the aspect, the @nt{aspect_definition} shall be an @nt{identifier}, and the
1676 @nt{identifier} shall be one of the identifiers specific to the identified
1677 aspect.]}
1678 @end{Itemize}
1679
1680 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1681 @ChgAdded{Version=[3],Text=[The usage names in an @nt{aspect_definition}
1682 @Redundant[ are not resolved at the point of the associated declaration, but
1683 rather] are resolved at the end of the immediately enclosing declaration list.]}
1684
1685 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1686 @ChgAdded{Version=[3],Text=[If the associated declaration is for a subprogram or
1687 entry, the names of the formal parameters are directly visible within the
1688 @nt{aspect_definition}, as are certain attributes, as specified elsewhere in
1689 this International Standard for the identified aspect. If the associated
1690 declaration is a @nt{type_declaration}, within the @nt{aspect_definition} the
1691 names of any components are directly visible, and the name of the first subtype
1692 denotes the current instance of the type (see
1693 @RefSecNum{The Context of Overload Resolution}). If the associated declaration
1694 is a @nt{subtype_declaration}, within the @nt{aspect_definition} the name of
1695 the new subtype denotes the current instance of the subtype.]}
1696 @end{Resolution}
1697
1698 @begin{Legality}
1699 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1700 @ChgAdded{Version=[3],Text=[If the first freezing point of the associated entity
1701 comes before the end of the immediately enclosing declaration list, then each
1702 usage name in the @nt{aspect_definition} shall resolve to the same entity at the
1703 first freezing point as it does at the end of the immediately enclosing
1704 declaration list.]}
1705
1706 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1707 @ChgAdded{Version=[3],Text=[At most one occurrence of each @nt{aspect_mark} is
1708 allowed within a single @nt{aspect_specification}. The aspect identified by the
1709 @nt{aspect_mark} shall be an aspect that can be specified for the associated
1710 entity (or view of the entity defined by the associated declaration).]}
1711
1712 @begin{Ramification}
1713 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0116-1]}
1714 @ChgAdded{Version=[4],Text=[This rule prevents multiple specifications in the same
1715 @nt{aspect_specification}. Rules in @RefSecNum{Operational and Representation Aspects} prevent multiple specifications in
1716 different @nt{aspect_specification}s (on different views of the same type,
1717 for instance) or between operational or representation items and
1718 an @nt{aspect_specification}, even for aspects that are neither operational
1719 nor representation aspects.]}
1720
1721 @end{Ramification}
1722
1723 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1724 @ChgAdded{Version=[3],Text=[The @nt{aspect_definition} associated with a given
1725 @nt{aspect_mark} may be omitted only when the @nt{aspect_mark} identifies an
1726 aspect of a boolean type, in which case it is equivalent to the
1727 @nt{aspect_definition} being specified as True.]}
1728
1729 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1730 @ChgAdded{Version=[3],Text=[If the @nt{aspect_mark} includes
1731 'Class, then the associated entity shall be a tagged type or a primitive
1732 subprogram of a tagged type.]}
1733
1734 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1735 @ChgAdded{Version=[3],Text=[There are no language-defined aspects that
1736 may be specified on a @nt{renaming_declaration},
1737 a @nt{generic_formal_parameter_declaration}, a @nt{subunit}, a @nt{package_body},
1738 a @nt{task_body}, a @nt{protected_body}, or a @nt{body_stub} other than a
1739 @nt{subprogram_body_stub}.]}
1740 @begin{Discussion}
1741 @ChgRef{Version=[3],Kind=[AddedNormal]}
1742 @ChgAdded{Version=[3],Text=[Implementation-defined aspects can be allowed on
1743 these, of course; the implementation will need to define the semantics. In
1744 particular, the implementation will need to define actual type matching
1745 rules for any aspects allowed on formal types; there are no default matching
1746 rules defined by the language.]}
1747 @end{Discussion}
1748
1749 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1750 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0105-1]}
1751 @ChgAdded{Version=[3],Text=[A language-defined aspect shall not be specified in
1752 an @nt{aspect_specification} given on a
1753 @Chg{Version=[4],New=[],Old=[@nt{subprogram_body} or
1754 @nt{subprogram_body_stub} that is a ]}completion of @Chg{Version=[4],New=[a
1755 subprogram or generic subprogram],Old=[another declaration]}.]}
1756
1757 @begin{Reason}
1758 @ChgRef{Version=[3],Kind=[AddedNormal]}
1759 @ChgAdded{Version=[3],Text=[Most language-defined aspects (for example,
1760 preconditions) are intended to be available to callers, and specifying them
1761 on a body that has a separate declaration hides them from callers. Specific
1762 language-defined aspects may allow this, but they have to do so explicitly
1763 (by defining an alternative @LegalityName), and provide any needed rules
1764 about visibility. Note that this rule does not apply to
1765 implementation-defined aspects, so implementers need to carefully define
1766 whether such aspects can be applied to bodies and stubs, and what happens
1767 if they are specified on both the declaration and body of a unit.]}
1768 @end{Reason}
1769
1770 @ChgRef{Version=[4],Kind=[Added],ARef=[AI05-0183-1],ARef=[AI12-0138-1]}
1771 @ChgAdded{Version=[4],Text=[If an aspect of a derived type is inherited from an
1772 ancestor type and has the boolean value True, the inherited value shall not be
1773 overridden to have the value False for the derived type, unless otherwise
1774 specified in this International Standard.]}
1775
1776 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1777 @ChgAdded{Version=[4],Text=[Certain type-related aspects are defined to be
1778 @i<nonoverridable>; all such aspects are specified using
1779 an @nt{aspect_definition} that is a @nt{name}.@Defn2{Term=[nonoverridable],Sec=[aspect]}]}
1780
1781 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1782 @ChgAdded{Version=[4],Text=[If a nonoverridable aspect is directly specified
1783 for a type @i<T>, then any explicit specification of that aspect for any
1784 other descendant of @i<T> shall be @i<confirming>;@PDefn2{Term=[confirming],Sec=[nonoverridable aspect]}
1785 that is, the specified @nt{name} shall @i<match>@Defn2{Term=[match],Sec=[value of nonoverridable aspect]}
1786 the inherited aspect, meaning that the specified @nt{name} shall denote the
1787 same declarations as would the inherited @nt{name}.]}
1788
1789 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1790 @ChgAdded{Version=[4],Text=[If a full type has a partial view, and a given
1791 nonoverridable aspect is allowed for both the full view and the partial view,
1792 then the given aspect for the partial view and the full view shall be the same:
1793 the aspect shall be directly specified only on the partial view; if the full
1794 type inherits the aspect, then a matching definition shall be specified
1795 (directly or by inheritance) for the partial view.]}
1796
1797 @begin{Ramification}
1798 @ChgAdded{Version=[4],Text=[In order to enforce these rules without breaking
1799 privacy, we cannot allow a private type that could have a particular
1800 overridable aspect to have a hidden definition of that aspect. There is no
1801 problem if the private type does not allow the aspect (as the
1802 aspect could not be specified on descendants in that case).]}
1803 @end{Ramification}
1804
1805 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1806 @ChgAdded{Version=[4],Text=[@PDefn{generic contract issue}
1807 In addition to the places where
1808 @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
1809 these rules about nonoverridable aspects also apply in the private part
1810 of an instance of a generic unit.]}
1811
1812 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1813 @ChgAdded{Version=[4],Text=[@Redundant[The Default_Iterator, Iterator_Element,
1814 Implicit_Dereference, Constant_Indexing, and Variable_Indexing aspects
1815 are nonoverridable.]]}
1816
1817 @begin{Discussion}
1818 @ChgRef{Version=[4],Kind=[AddedNormal]}
1819 @ChgAdded{Version=[4],Text=[We don't need an assume-the-worst rule for most
1820 nonoverridable aspects as they only work on tagged types and deriving from
1821 formal tagged types is not allowed in generic bodies. In the case of
1822 Implicit_Dereference, a derivation in a generic body does not cause problems
1823 (the ancestor necessarily cannot have the aspect, else specifying the aspect
1824 would be illegal), as there could be no place with visibility on both aspects.]}
1825 @end{Discussion}
1826
1827 @end{Legality}
1828
1829 @begin{StaticSem}
1830
1831 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1832 @ChgAdded{Version=[3],Type=[Leading],Text=[Depending on which aspect is
1833 identified by the @nt{aspect_mark}, an @nt{aspect_definition} specifies:]}
1834 @begin{Itemize}
1835 @ChgRef{Version=[3],Kind=[AddedNormal]}
1836 @ChgAdded{Version=[3],Text=[a @nt{name} that denotes a subprogram, object, or
1837 other kind of entity;]}
1838
1839 @ChgRef{Version=[3],Kind=[AddedNormal]}
1840 @ChgAdded{Version=[3],Text=[an @nt{expression}, which is either evaluated to
1841 produce a single value, or which (as in a precondition) is to be evaluated at
1842 particular points during later execution; or]}
1843
1844 @ChgRef{Version=[3],Kind=[AddedNormal]}
1845 @ChgAdded{Version=[3],Text=[an @nt{identifier} specific to the aspect.]}
1846 @end{Itemize}
1847
1848 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1849 @ChgAdded{Version=[3],Type=[Leading],Text=[The identified aspect of the
1850 associated entity, or in some cases, the view of the entity defined by the
1851 declaration, is as specified by the @nt{aspect_definition} (or by the default of
1852 True when boolean). Whether an @nt{aspect_specification} @i<applies> to an entity or
1853 only to the particular view of the entity defined by the declaration is
1854 determined by the @nt{aspect_mark} and the kind of entity. The following aspects
1855 are view specific:@PDefn2{Term=[applies],Sec=[aspect]}]}
1856
1857 @begin{Itemize}
1858
1859 @ChgRef{Version=[3],Kind=[AddedNormal]}
1860 @ChgAdded{Version=[3],Text=[An aspect specified on an @nt{object_declaration};]}
1861
1862 @ChgRef{Version=[3],Kind=[AddedNormal]}
1863 @ChgAdded{Version=[3],Text=[An aspect specified on a @nt{subprogram_declaration};]}
1864
1865 @ChgRef{Version=[3],Kind=[AddedNormal]}
1866 @ChgAdded{Version=[3],Text=[An aspect specified on a @nt{renaming_declaration}.]}
1867
1868 @end{Itemize}
1869
1870 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1871 @ChgAdded{Version=[3],Text=[All other @nt{aspect_specification}s are associated
1872 with the entity, and @i<apply> to all views of the entity, unless otherwise
1873 specified in this International Standard.@PDefn2{Term=[applies],Sec=[aspect]}]}
1874
1875 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1876 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0106-1]}
1877 @ChgAdded{Version=[3],Type=[Leading],Text=[If the @nt{aspect_mark} includes
1878 'Class@Chg{Version=[4],New=[ (a @i<class-wide
1879 aspect>)@Defn{class-wide aspect}@Defn2{Term=[aspect],Sec=[class-wide]}],Old=[]},
1880 then@Chg{Version=[4],New=[, unless specified otherwise for a particular
1881 class-wide aspect],Old=[]}:]}
1882 @begin{Itemize}
1883
1884 @ChgRef{Version=[3],Kind=[AddedNormal]}
1885 @ChgAdded{Version=[3],Text=[if the associated entity is a tagged type, the
1886 specification @i<applies> to all descendants of the type;@PDefn2{Term=[applies],Sec=[aspect]}]}
1887
1888 @ChgRef{Version=[3],Kind=[AddedNormal]}
1889 @ChgAdded{Version=[3],Text=[if the associated entity is a primitive subprogram
1890 of a tagged type @i<T>, the specification @i<applies> to the corresponding primitive
1891 subprogram of all descendants of @i<T>.@PDefn2{Term=[applies],Sec=[aspect]}]}
1892 @end{Itemize}
1893
1894 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0229-1]}
1895 @ChgAdded{Version=[3],Text=[All specifiable operational and representation
1896 attributes may be specified with an @nt{aspect_specification} instead of an
1897 @nt{attribute_definition_clause} (see
1898 @RefSecNum{Operational and Representation Attributes}).]}
1899
1900 @begin{Ramification}
1901 @ChgRef{Version=[3],Kind=[AddedNormal]}
1902 @ChgAdded{Version=[3],Text=[The name of the aspect is the same as that of the attribute
1903 (see @RefSecNum{Operational and Representation Attributes}), so the @nt{aspect_mark}
1904 is the @nt{attribute_designator} of the attribute.]}
1905 @end{Ramification}
1906
1907 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1908 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0154-1]}
1909 @ChgAdded{Version=[3],Text=[Any aspect specified by a representation pragma
1910 or library unit pragma that has a @nt{local_name} as its single argument
1911 may be specified by an @nt{aspect_specification}, with the entity being the
1912 @nt{local_name}. The @nt{aspect_definition} is expected to be of type Boolean.
1913 The expression shall be static.@Chg{Version=[4],New=[ Notwithstanding what
1914 this International Standard says elsewhere, the expression of an aspect that
1915 can be specified by a library unit pragma is resolved and evaluated at the
1916 point where it occurs in the @nt{aspect_specification}@Redundant[, rather
1917 than the first freezing point of the associated
1918 package].@Defn{Notwithstanding}],Old=[]}]}
1919
1920 @begin{Ramification}
1921 @ChgRef{Version=[3],Kind=[AddedNormal]}
1922 @ChgAdded{Version=[3],Text=[The name of the aspect is the same as that of the
1923 pragma (see @RefSecNum{Operational and Representation Aspects}), so the
1924 @nt{aspect_mark} is the name of the pragma.]}
1925 @end{Ramification}
1926
1927 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1928 @ChgAdded{Version=[3],Text=[In addition,
1929 other operational and representation aspects not associated with specifiable
1930 attributes or representation pragmas may be specified, as specified elsewhere
1931 in this International Standard.]}
1932
1933 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1934 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0138-1]}
1935 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[If an aspect of a
1936 derived type is inherited from an ancestor type and has the boolean value True,
1937 the inherited value shall not be overridden to have the value False for the
1938 derived type, unless otherwise specified in this International Standard.]}]}
1939
1940 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1941 @ChgAdded{Version=[3],Text=[If a @LegalityName or @StaticSemTitle rule only
1942 applies when a particular aspect has been specified, the aspect is considered to
1943 have been specified only when the @nt{aspect_specification} or
1944 @nt{attribute_definition_clause} is visible (see @RefSecNum{Visibility}) at the point
1945 of the application of the rule.]}
1946
1947 @begin{Reason}
1948 @ChgRef{Version=[3],Kind=[AddedNormal]}
1949 @ChgAdded{Version=[3],Text=[Some rules only apply when an aspect has been
1950 specified (for instance, an indexable type is one that has aspect
1951 Variable_Indexing specified). In order to prevent privacy breaking, this can
1952 only be true when the specification of the aspect is visible. In particular,
1953 if the Variable_Indexing aspect is specified on the full view of a private
1954 type, the private type is not considered an indexable type.]}
1955 @end{Reason}
1956
1957 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1958 @ChgAdded{Version=[3],Text=[Alternative legality and semantics rules may apply
1959 for particular aspects, as specified elsewhere in this International Standard.]}
1960
1961 @end{StaticSem}
1962
1963 @begin{Runtime}
1964 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1965 @ChgAdded{Version=[3],Text=[At the freezing point of the associated entity, the
1966 @nt{aspect_specification} is elaborated. The elaboration of the
1967 @nt{aspect_specification} includes the evaluation of the @nt{name} or
1968 @nt{expression}, if any, unless the aspect itself is an expression. If the
1969 corresponding aspect represents an expression (as in a precondition), the
1970 elaboration has no effect; the expression is evaluated later at points
1971 within the execution as specified elsewhere in this International Standard for
1972 the particular aspect.]}
1973 @end{Runtime}
1974
1975 @begin{ImplPerm}
1976 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1977 @ChgAdded{Version=[3],Text=[Implementations may support implementation-defined
1978 aspects. The @nt{aspect_specification} for an implementation-defined aspect may
1979 use an implementation-defined syntax for the @nt{aspect_definition}, and may
1980 follow implementation-defined legality and semantics rules.]}
1981 @begin{Discussion}
1982 @ChgRef{Version=[3],Kind=[AddedNormal]}
1983 @ChgAdded{Version=[3],Text=[The intent is to allow implementations to support
1984 aspects that are defined, for example, by a @nt{subtype_indication} rather
1985 than an @nt{expression} or a @nt{name}. We chose not to try to enumerate all
1986 possible @nt{aspect_definition} syntaxes, but to give implementations maximum
1987 freedom. Unrecognized aspects are illegal whether or not they use custom
1988 syntax, so this freedom does not reduce portability.]}
1989 @end{Discussion}
1990 @ChgImplDef{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
1991 Text=[Implementation-defined aspects, inluding the syntax for specifying
1992 such aspects and the legality rules for such aspects.]}]}
1993 @end{ImplPerm}
1994
1995 @begin{Extend2005}
1996 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0229-1],ARef=[AI05-0267-1]}
1997 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1998 Aspect specifications are new.]}
1999 @end{Extend2005}
2000
2001 @begin{Incompatible2012}
2002 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0154-1]}
2003 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
2004 Added a clarification that aspects that correspond to library unit pragmas
2005 are resolved and evaluated immediately. This is incompatible, as a
2006 reference to an entity defined after the aspect will now be illegal.
2007 However, this would have
2008 require retroactive enforcement of such aspects, which is a new
2009 capability not available from the associated pragma, and moreover
2010 no known Ada 2012 implementation has ever allowed late evaluation of
2011 such aspects. As such, there should be no practical incompatibility.]}
2012 @end{Incompatible2012}
2013
2014 @begin{Diffword2012}
2015 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI125-0105-1]}
2016 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the wording so that the restriction
2017 against language-defined aspects on subprogram completions includes
2018 completions that are expressions functions and null procedures.]}
2019
2020 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI125-0106-1]}
2021 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Defined class-wide aspect
2022 for use in rules in @RefSecNum{Stream-oriented attributes}.]}
2023
2024 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI125-0138-1]}
2025 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added a definition of
2026 nonoverridable aspects. This is necessary to prevent generic contract
2027 problems with formal derived types.]}
2028 @end{Diffword2012}
2029
2030
2031 @LabeledRevisedClause{Version=[3],New=[Packed Types],Old=[Pragma Pack]}
2032
2033 @begin{Intro}
2034 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2035 @redundant[@Chg{Version=[3],New=[The Pack aspect having the value True],Old=[A
2036 @nt{pragma} Pack]} specifies that storage minimization should be the main
2037 criterion when selecting the representation of a composite type.]
2038 @end{Intro}
2039
2040 @begin{NotIso}
2041 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2
2042 through 4 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
2043 should be deleted if the paragraphs are ever renumbered.}
2044 @end{NotIso}
2045
2046 @begin{MetaRules}
2047 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
2048 @ChgAdded{Version=[4],Text=[If the default representation already uses
2049 minimal storage for a particular type, aspect Pack might not cause any
2050 representation change. It follows that aspect Pack should always be allowed,
2051 even when it has no effect on representation.]}
2052
2053 @ChgRef{Version=[4],Kind=[AddedNormal]}
2054 @ChgAdded{Version=[4],Text=[As a consequence, the chosen representation for a
2055 packed type may change during program maintenance even if the type is
2056 unchanged (in particular, if other representation aspects change on a part of
2057 the type). This is different than the behavior of most other representation
2058 aspects, whose properties remain guaranteed no matter what changes are made to
2059 other aspects.]}
2060
2061 @ChgRef{Version=[4],Kind=[AddedNormal]}
2062 @ChgAdded{Version=[4],Text=[Therefore, aspect Pack should not be used to
2063 achieve a representation required by external criteria. For instance, setting
2064 Component_Size to 1 should be preferred over using aspect Pack to ensure an
2065 array of bits. If future maintenance would make the array components aliased,
2066 independent, or atomic, the program would become illegal if Component_Size is
2067 used (immediately identifying a problem) while the aspect Pack version would
2068 simply change representations (probably causing a hard-to-find bug).]}
2069 @end{MetaRules}
2070
2071 @begin{Syntax}
2072 @begin{SyntaxText}
2073 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
2074 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
2075 @nt{pragma} Pack is as follows:]}
2076 @end{SyntaxText}
2077
2078 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
2079 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
2080 Text=[@key{pragma} @prag(Pack)(@SynI{first_subtype_}@Syn2{local_name});]}>
2081 @end{Syntax}
2082
2083 @begin{Legality}
2084 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
2085 @ChgDeleted{Version=[3],Text=[The @SynI{first_subtype_}@nt{local_name} of a
2086 @nt{pragma} Pack shall denote a composite subtype.]}
2087 @end{Legality}
2088
2089 @begin{StaticSem}
2090 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2091 @ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{A fake to get a conditional Leading}
2092 @Chg{Version=[3],New=[For a full type declaration of a composite type, the
2093 following language-defined representation aspect may be specified:],
2094 Old=[@PDefn2{Term=[representation pragma], Sec=(Pack)}
2095 @PDefn2{Term=[pragma, representation], Sec=(Pack)}
2096 @Chg{Version=[3],New=[@PDefn2{Term=[representation aspect], Sec=(packing)}],
2097 Old=[@PDefn2{Term=[aspect of representation], Sec=(packing)}
2098 @Defn2{Term=[packing], Sec=(aspect of representation)}]}
2099 @Defn{packed}
2100 A @nt{pragma} Pack specifies the @i{packing} aspect of representation;
2101 the type (or the extension part) is said to be @i{packed}.
2102 For a type extension, the parent part is packed as for the parent
2103 type, and a @nt{pragma} Pack causes packing only of the extension part.]}
2104
2105 @begin{Description}
2106 @ChgRef{Version=[3],Kind=[Added]}
2107 @ChgAdded{Version=[3],Text=[Pack@\The type of aspect Pack is Boolean. When
2108 aspect Pack is True for a type, the type (or the extension part) is said to be
2109 @i{packed}. For a type extension, the parent part is packed as for the parent
2110 type, and specifying Pack causes packing only of the extension part.
2111 @Defn{packed}@AspectDefn{Pack}]}
2112
2113 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pack],
2114 Text=[@ChgAdded{Version=[3],Text=[Minimize storage when laying out records
2115 and arrays.]}]}
2116
2117 @ChgRef{Version=[3],Kind=[Added]}
2118 @ChgAdded{Version=[3],NoPrefix=[T],Text=[If directly specified, the
2119 @nt{aspect_definition} shall be a static expression. If not specified
2120 (including by inheritance), the aspect is False.]}
2121 @end{Description}
2122
2123 @begin{Ramification}
2124 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2125 The only high level semantic effect of @Chg{Version=[3],New=[specifying the],Old=[a @nt{pragma}]
2126 Pack@Chg{Version=[3],New=[ aspect],Old=[]}
2127 is @Chg{Version=[3],New=[potential loss of ],Old=[]}independent
2128 addressability (see @RefSec{Shared Variables}).]}
2129 @end{Ramification}
2130 @end{StaticSem}
2131
2132 @begin{ImplAdvice}
2133 If a type is packed, then the implementation should try to minimize
2134 storage allocated to objects of the type,
2135 possibly at the expense of speed of accessing components,
2136 subject to reasonable complexity in addressing calculations.
2137 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2138 Text=[Storage allocated to objects of a packed type should be minimized.]}]}
2139 @begin{Ramification}
2140 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2141 @Chg{Version=[3],New=[Specifying the],Old=[A @nt{pragma}]}
2142 Pack@Chg{Version=[3],New=[ aspect],Old=[]} is for gaining space efficiency,
2143 possibly at the expense of time.
2144 If more explicit control over representation is desired,
2145 then a @nt{record_representation_clause},
2146 a Component_Size clause,
2147 or a Size clause should be used instead of,
2148 or in addition to,
2149 @Chg{Version=[3],New=[the],Old=[a @nt{pragma}]}
2150 Pack@Chg{Version=[3],New=[ aspect],Old=[]}.
2151 @end{Ramification}
2152
2153 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2154 @ChgRef{Version=[4],Kind=[DeletedAdded],ARef=[AI12-0001-1]}
2155 @ChgDeleted{Version=[4],Text=[@Chg{Version=[2],New=[If a packed type has a
2156 component that is not of a by-reference type and has no aliased part, then such
2157 a component need not be aligned according to the Alignment of its subtype; in
2158 particular it need not be allocated on a storage element
2159 boundary.@Comment{No "should" here; thus no ImplAdvice entry. This really
2160 qualifies the item above}],Old=[]}]}
2161
2162 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2163 @Chg{Version=[3],New=[@PDefn2{Term=[recommended level of support], Sec=(aspect Pack)}],
2164 Old=[@PDefn2{Term=[recommended level of support], Sec=(pragma Pack)}]}
2165 The recommended level of support for
2166 @Chg{Version=[3],New=[the],Old=[@nt{pragma}]}
2167 Pack@Chg{Version=[3],New=[ aspect],Old=[]} is:
2168 @begin{Itemize}
2169 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0001-1]}
2170 @ChgAdded{Version=[4],Text=[Any component of a packed type that is of a
2171 by-reference type, that is specified as independently addressable, or that
2172 contains an aliased part, shall be aligned according to the alignment of its
2173 subtype.]}
2174
2175 @begin{Ramification}
2176 @ChgRef{Version=[4],Kind=[AddedNormal]}
2177 @ChgAdded{Version=[4],Text=[This also applies to atomic components. "Atomic"
2178 implies "specified as independently addressable", so we don't need to mention
2179 atomic here.]}
2180
2181 @ChgRef{Version=[4],Kind=[AddedNormal]}
2182 @ChgAdded{Version=[4],Text=[Other components do not have to respect the
2183 alignment of the subtype when packed; in many cases, the Recommended Level of
2184 Support will require the alignment to be ignored.]}
2185 @end{Ramification}
2186
2187 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
2188 For a packed record type, the components should be packed as tightly as
2189 possible subject to @Chg{Version=[4],New=[the above alignment
2190 requirements, ],Old=[]}the Sizes of the component subtypes, and
2191 @Chg{Version=[4],New=[],Old=[subject to ]}any
2192 @nt{record_representation_clause} that applies to the type; the implementation
2193 may, but need not, reorder components or cross aligned word boundaries to
2194 improve the packing. A component whose Size is greater than the word size may
2195 be allocated an integral number of words.
2196
2197 @begin{Ramification}
2198 The implementation can always allocate an integral number of words for a
2199 component that will not fit in a word. The rule also allows small component
2200 sizes to be rounded up if such rounding does not waste space. For example,
2201 if Storage_Unit = 8, then a component of size 8 is probably more efficient
2202 than a component of size 7 plus a 1-bit gap (assuming the gap is needed
2203 anyway).
2204 @end{Ramification}
2205
2206 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
2207 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
2208 For a packed array type, if the @Chg{Version=[3],New=[], Old=[component
2209 subtype's ]}Size@Chg{Version=[3],New=[ of the component subtype],Old=[]} is
2210 less than or equal to the word size@Chg{Version=[3],New=[],Old=[, and
2211 Component_Size is not specified for the type]}, Component_Size should be less
2212 than or equal to the Size of the component subtype, rounded up to the nearest
2213 factor of the word size@Chg{Version=[4],New=[, unless this would violate
2214 the above alignment requirements],Old=[]}.
2215
2216 @begin{Ramification}
2217 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0001-1]}
2218 @ChgDeleted{Version=[4],Text=[If a component subtype is aliased,
2219 its Size will generally be a multiple of Storage_Unit,
2220 so it probably won't get packed very tightly.]}
2221 @end{Ramification}
2222 @end{Itemize}
2223 @ChgImplAdvice{Version=[3],Kind=[Revised],InitialVersion=[2],
2224 Text=[@ChgAdded{Version=[2],
2225 Text=[The recommended level of support for @Chg{Version=[3],New=[the],Old=[pragma]}
2226 Pack@Chg{Version=[3],New=[ aspect],Old=[]} should be
2227 followed.]}]}
2228 @end{ImplAdvice}
2229
2230 @begin{DiffWord95}
2231 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
2232 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2233 @ChgAdded{Version=[2],Text=[Added clarification that
2234 @Chg{Version=[3],New=[the],Old=[pragma]} Pack@Chg{Version=[3],New=[ aspect],Old=[]} can
2235 ignore alignment requirements on types that don't have by-reference or
2236 aliased parts. This was always intended, but there was no wording to that
2237 effect.]}
2238 @end{DiffWord95}
2239
2240 @begin{Extend2005}
2241 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
2242 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2243 Aspect Pack is new; @nt{pragma} Pack is now obsolescent.]}
2244 @end{Extend2005}
2245
2246 @begin{DiffWord2005}
2247 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1]}
2248 @ChgAdded{Version=[3],Text=[@b<Correction:> Fixed so that the
2249 presence or absence of a confirming Component_Size representation
2250 clause does not change the meaning of the Pack aspect.]}
2251 @end{DiffWord2005}
2252
2253 @begin{DiffWord2012}
2254 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
2255 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Fixed so that the
2256 Recommended Level of Support does not require packing of
2257 components for which such packing would violate other representation
2258 items or aspects. This is not incompatible, as either such Pack
2259 aspects were treated as illegal or the Recommended Level of Support
2260 was ignored as impractical, neither of which would change the
2261 behavior of any working programs. (Other behavior cannot be justifed
2262 from the Standard.)]}
2263 @end{DiffWord2012}
2264
2265
2266
2267 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
2268 @LabeledRevisedClause{Version=[1],New=[Operational and Representation Attributes], Old=[Representation Attributes]}
2269
2270 @begin{Intro}
2271 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
2272 @redundant[@Defn{representation attribute}
2273 @Defn2{Term=[attribute], Sec=(representation)}
2274 The values of certain implementation-dependent characteristics can be
2275 obtained by interrogating appropriate
2276 @Chg{New=[operational or ],Old=[]}representation attributes.
2277 @RootDefn2{Term=[attribute], Sec=(specifying)}
2278 Some of these attributes are specifiable via an
2279 @nt{attribute_definition_clause}.]
2280 @end{Intro}
2281
2282 @begin{MetaRules}
2283 In general, the meaning of a given attribute should not depend on
2284 whether the attribute was specified via an
2285 @nt{attribute_definition_clause},
2286 or chosen by default by the implementation.
2287 @end{MetaRules}
2288
2289 @begin{Syntax}
2290 @Syn{lhs=<attribute_definition_clause>,rhs="
2291 @key{for} @Syn2{local_name}@SingleQuote@Syn2{attribute_designator} @key{use} @Syn2{expression};
2292 | @key{for} @Syn2{local_name}@SingleQuote@Syn2{attribute_designator} @key{use} @Syn2{name};"}
2293 @end{Syntax}
2294
2295 @begin{Resolution}
2296 For an @nt{attribute_definition_clause} that specifies
2297 an attribute that denotes a value,
2298 the form with an @nt{expression} shall be used.
2299 Otherwise, the form with a @nt{name} shall be used.
2300
2301 @PDefn2{Term=[expected type],
2302 Sec=(attribute_definition_clause expression or name)}
2303 For an @nt{attribute_definition_clause} that specifies
2304 an attribute that denotes a value or an object,
2305 the expected type for the expression or @nt{name}
2306 is that of the attribute.
2307 @PDefn2{Term=[expected profile],
2308 Sec=(attribute_definition_clause name)}
2309 For an @nt{attribute_definition_clause} that specifies
2310 an attribute that denotes a subprogram,
2311 the expected profile for the @nt{name}
2312 is the profile required for the attribute.
2313 For an @nt{attribute_definition_clause} that specifies
2314 an attribute that denotes some other kind of entity,
2315 the @nt{name} shall resolve to denote an entity of the appropriate
2316 kind.
2317 @begin{Ramification}
2318 For example, the Size attribute is of type @i{universal_integer}.
2319 Therefore, the expected type for Y in @lquotes@;@key[for] X'Size @key[use] Y;@rquotes@; is
2320 @i{universal_integer},
2321 which means that Y can be of any integer type.
2322 @end{Ramification}
2323 @begin{Discussion}
2324 For attributes that denote subprograms, the required profile is indicated
2325 separately for the individual attributes.
2326 @end{Discussion}
2327 @begin{Ramification}
2328 @Leading@;For an @nt{attribute_definition_clause} with a @nt{name},
2329 the @nt{name} need not statically denote the entity it denotes.
2330 For example, the following kinds of things are allowed:
2331 @begin{Example}
2332 @key[for] Some_Access_Type'Storage_Pool @key[use] Storage_Pool_Array(I);
2333 @key[for] Some_Type'Read @key[use] Subprogram_Pointer.@key[all];
2334 @end{Example}
2335 @end{Ramification}
2336 @end{Resolution}
2337
2338 @begin{Legality}
2339 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
2340 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2341 @RootDefn{specifiable (of an attribute and for an entity)}
2342 @RootDefn2{Term=[attribute], Sec=(specifiable)}
2343 An @nt{attribute_designator} is allowed in an
2344 @nt{attribute_definition_clause} only if this International Standard
2345 explicitly allows it,
2346 or for an implementation-defined attribute
2347 if the implementation allows it.
2348 @Chg{Version=[3],New=[@PDefn2{Term=[representation aspect], Sec=(specifiable attributes)}],
2349 Old=[@PDefn2{Term=[aspect of representation], Sec=(specifiable attributes)}]}
2350 Each specifiable attribute constitutes an
2351 @Chg{New=[@PDefn2{Term=[operational aspect], Sec=(specifiable attributes)}
2352 operational aspect or ],Old=[]}aspect of representation@Chg{Version=[3],New=[;
2353 the name of the aspect is that of the attribute],Old=[]}.
2354 @begin{Discussion}
2355 For each specifiable attribute,
2356 we generally say something like,
2357 @lquotes@;The ... attribute may be specified for ... via
2358 an @nt{attribute_definition_clause}.@rquotes@;
2359
2360 The above wording allows for
2361 T'Class'Alignment, T'Class'Size, T'Class'Input, and T'Class'Output
2362 to be specifiable.
2363
2364 A specifiable attribute is not necessarily
2365 specifiable for all entities for which it is defined.
2366 For example, one is allowed to ask T'Component_Size for an array
2367 subtype T, but @lquotes@;@key[for] T'Component_Size @key[use] ...@rquotes@;
2368 is only allowed if T is a first subtype,
2369 because Component_Size is a type-related aspect.
2370 @end{Discussion}
2371
2372 For an @nt{attribute_definition_clause} that specifies
2373 an attribute that denotes a subprogram,
2374 the profile shall be mode conformant with the one
2375 required for the attribute,
2376 and the convention shall be Ada.
2377 Additional requirements are defined for particular attributes.
2378 @Defn2{Term=[mode conformance],Sec=(required)}
2379 @begin{Ramification}
2380 @Leading@;This implies, for example, that if one writes:
2381 @begin{Example}
2382 @key[for] T'Read @key[use] R;
2383 @end{Example}
2384
2385 R has to be a procedure with two parameters with the appropriate
2386 subtypes and modes as shown in
2387 @RefSecNum{Stream-Oriented Attributes}.
2388 @end{Ramification}
2389 @end{Legality}
2390
2391 @begin{StaticSem}
2392 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00270-01]}
2393 @Defn{Address clause}
2394 @Defn{Alignment clause}
2395 @Defn{Size clause}
2396 @Defn{Component_Size clause}
2397 @Defn{External_Tag clause}
2398 @Defn{Small clause}
2399 @Defn{Bit_Order clause}
2400 @Defn{Storage_Pool clause}
2401 @Defn{Storage_Size clause}@Chg{Version=[2],New=[
2402 @Defn{Stream_Size clause}],Old=[]}
2403 @Defn{Read clause}
2404 @Defn{Write clause}
2405 @Defn{Input clause}
2406 @Defn{Output clause}
2407 @Defn{Machine_Radix clause}
2408 A @i{Size clause} is an @nt{attribute_definition_clause} whose
2409 @nt{attribute_designator} is Size.
2410 Similar definitions apply to the other specifiable attributes.
2411 @begin{Honest}
2412 @PDefn2{Term=[type-related], Sec=(attribute_definition_clause)}
2413 @PDefn2{Term=[subtype-specific], Sec=(attribute_definition_clause)}
2414 An @nt{attribute_definition_clause}
2415 is type-related or subtype-specific if the @nt{attribute_designator}
2416 denotes a type-related or subtype-specific attribute, respectively.
2417 @end{Honest}
2418
2419 @Defn{storage element}
2420 @IndexSee{Term=[byte],See=(storage element)}
2421 A @i{storage element} is
2422 an addressable element of storage in the machine.
2423 @Defn{word}
2424 A @i{word} is the largest amount of storage that can be conveniently and
2425 efficiently manipulated by the hardware,
2426 given the implementation's run-time model.
2427 A word consists of an integral number of storage elements.
2428 @begin{Discussion}
2429 A storage element is not intended to be a single bit,
2430 unless the machine can efficiently address individual bits.
2431 @end{Discussion}
2432 @begin{Ramification}
2433 For example, on a machine with 8-bit storage elements,
2434 if there exist 32-bit integer registers,
2435 with a full set of arithmetic and logical instructions to manipulate those
2436 registers, a word ought to be 4 storage elements @em that is, 32 bits.
2437 @end{Ramification}
2438 @begin{Discussion}
2439 The @lquotes@;given the implementation's run-time model@rquotes@; part is
2440 intended to imply that, for example, on an 80386 running MS-DOS,
2441 the word might be 16 bits, even though the hardware can support 32
2442 bits.
2443
2444 A word is what ACID refers to as a @lquotes@;natural hardware
2445 boundary@rquotes@;.
2446
2447 Storage elements may, but need not be, independently addressable
2448 (see @RefSec{Shared Variables}).
2449 Words are expected to be independently addressable.
2450 @end{Discussion}
2451
2452 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
2453 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1]}
2454 @ChgAdded{Version=[2],Text=[@Defn{machine scalar}
2455 A @i{machine scalar} is an amount of storage that can be conveniently and
2456 efficiently loaded, stored, or operated upon by the hardware. Machine scalars
2457 consist of an integral number of storage elements. The set of machine scalars
2458 is implementation defined, but @Chg{Version=[3],New=[includes],Old=[must include]}
2459 at least the storage element and
2460 the word. Machine scalars are used to interpret @nt{component_clause}s when the
2461 nondefault bit ordering applies.]}
2462 @ChgImplDef{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2463 Text=[The set of machine scalars.]}]}
2464 @begin{Ramification}
2465 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0092-1]}
2466 @ChgAdded{Version=[3],Text=[A single storage element is a machine scalar
2467 in all Ada implementations. Similarly, a word is a machine scalar in
2468 all implementations (although it might be the same as a storage element).
2469 An implementation may define other machine scalars that make sense on the
2470 target (a half-word, for instance).]}
2471 @end{Ramification}
2472
2473 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
2474 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0191-1]}
2475 @Chg{New=[The following representation attributes are defined: Address,
2476 Alignment, Size, Storage_Size,
2477 @Chg{Version=[3],New=[],Old=[and ]}Component_Size@Chg{Version=[3],New=[,
2478 Has_Same_Storage, and Overlaps_Storage],Old=[]}.],
2479 Old=[@Leading@;The following attributes are defined:]}
2480
2481 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
2482 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
2483 @Chg{New=[@nt{prefix}],Old=[prefix]} X that
2484 denotes an object, program unit, or label]}:
2485 @begin{Description}
2486 @Attribute{Prefix=<X>, AttrName=<Address>,
2487 Text=<Denotes the address of the first of the storage elements
2488 allocated to X. For a program unit or
2489 label, this value refers to the machine code associated with
2490 the corresponding body or @nt{statement}.
2491 The value of this attribute is of type System.Address.>}
2492
2493 @begin{Ramification}
2494 Here, the @lquotes@;first of the storage elements@rquotes@; is intended
2495 to mean the one with the lowest address;
2496 the endianness of the machine doesn't matter.
2497 @end{Ramification}
2498
2499 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0095-1]}
2500 @ChgAdded{Version=[3],NoPrefix=[T],Text=[The prefix of X'Address shall not statically denote
2501 a subprogram that has convention Intrinsic. X'Address raises Program_Error if X
2502 denotes a subprogram that has convention Intrinsic.]}
2503
2504 @NoPrefix@PDefn2{Term=[specifiable], Sec=(of Address for stand-alone
2505 objects and for program units)}
2506 @Defn{Address clause}
2507 @ChgNote{Removed Redundant here, as per AI-00114. Did not mark change, as it is
2508 AARM-only, not to the text of the item.}Address may be specified for
2509 stand-alone objects and for program units via an
2510 @nt{attribute_definition_clause}.@Chg{Version=[3],New=[@AspectDefn{Address}],Old=[]}
2511 @begin{Ramification}
2512 Address is not allowed for enumeration literals,
2513 predefined operators, derived task types,
2514 or derived protected types, since they are not program units.
2515
2516 @ChgRef{Version=[3],Kind=[AddedNormal]}
2517 @ChgAdded{Version=[3],Text=[Address is not allowed for intrinsic subprograms,
2518 either. That can be checked statically unless the prefix is a generic formal
2519 subprogram and the attribute reference is in the body of a generic unit.
2520 We define that case to raise Program_Error, in order that the compiler
2521 does not have to build a wrapper for intrinsic subprograms.]}
2522
2523 The validity of a given address depends on the run-time model;
2524 thus, in order to use Address clauses correctly,
2525 one needs intimate knowledge of the run-time model.
2526
2527 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2528 If the Address of an object is specified,
2529 any explicit or implicit initialization takes place as usual,
2530 unless @Chg{Version=[3],New=[the],Old=[a @nt{pragma}]} Import
2531 @Chg{Version=[3],New=[aspect ],Old=[]}is also specified for the object
2532 (in which case any necessary initialization is presumably
2533 done in the foreign language).
2534
2535 Any compilation unit containing an @nt<attribute_reference> of
2536 a given type depends semantically on the declaration of the package
2537 in which the type is declared, even if not mentioned
2538 in an applicable @nt<with_clause>
2539 @em see @RefSecNum{Compilation Units - Library Units}.
2540 In this case, it means that if a compilation unit contains
2541 X'Address, then it depends on the declaration of System.
2542 Otherwise, the fact that the value of Address is of
2543 a type in System wouldn't make sense;
2544 it would violate the @lquotes@;legality determinable via semantic
2545 dependences@rquotes@; @MetaRulesName.
2546
2547 AI83-00305 @em If X is a task type,
2548 then within the body of X,
2549 X denotes the current task object;
2550 thus, X'Address denotes the object's address.
2551
2552 Interrupt entries and their addresses are
2553 described in @RefSec{Interrupt Entries}.
2554
2555 If X is not allocated on a storage element boundary,
2556 X'Address points at the first of the storage elements
2557 that contains any part of X.
2558 This is important for the definition of the Position
2559 attribute to be sensible.
2560 @end{Ramification}
2561
2562 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Address],
2563 Text=[@ChgAdded{Version=[3],Text=[Machine address of an entity.]}]}
2564
2565 @end{Description}
2566 @EndPrefixType{}
2567 @end{StaticSem}
2568
2569 @begin{Erron}
2570 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
2571 @PDefn2{Term=(erroneous execution),Sec=(cause)}If an Address is specified,
2572 it is the programmer's responsibility to ensure that
2573 the address is valid@Chg{Version=[3],New=[ and appropriate for the entity and
2574 its use],Old=[]}; otherwise, program execution is erroneous.
2575
2576 @begin{Discussion}
2577 @ChgAdded{Version=[3],Text=[@ldquote@;Appropriate for the entity and its
2578 use@rdquote covers cases such as
2579 misaligned addresses, read-only code addresses for variable data objects (and
2580 nonexecutable data addresses for code units), and addresses which would
2581 force objects that are supposed to be independently addressable to not be.
2582 Such addresses may be @ldquote@;valid@rdquote as they designate locations that
2583 are accessible to the program, but the program execution is still erroneous
2584 (meaning that implementations do not have to worry about these cases).]}
2585 @end{Discussion}
2586 @end{Erron}
2587
2588 @begin{ImplAdvice}
2589 For an array X, X'Address should point at the first component of the
2590 array, and not at the array bounds.
2591 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2592 Text=[For an array X, X'Address should point at the first component of the
2593 array rather than the array bounds.]}]}
2594 @begin{Ramification}
2595 On the other hand, we have no advice to offer about
2596 discriminants and tag fields;
2597 whether or not the address points at them is
2598 not specified by the language.
2599 If discriminants are stored separately,
2600 then the Position of a discriminant might be negative,
2601 or might raise an exception.
2602 @end{Ramification}
2603
2604 @PDefn2{Term=[recommended level of support], Sec=(Address attribute)}
2605 @Leading@;The recommended level of support for the Address attribute is:
2606 @begin{Itemize}
2607 X'Address should produce a useful result if X is an
2608 object that is aliased or of a by-reference
2609 type, or is an entity whose Address has been specified.
2610 @begin{Reason}
2611 Aliased objects are the ones for which the
2612 Unchecked_Access attribute is allowed;
2613 hence, these have to be allocated on an addressable
2614 boundary anyway. Similar considerations apply to objects
2615 of a by-reference type.
2616
2617 An implementation need not go to any trouble
2618 to make Address work in other cases.
2619 For example, if an object X is not aliased and not of a by-reference type,
2620 and the implementation chooses to store it in a register,
2621 X'Address might return System.Null_Address
2622 (assuming registers are not addressable).
2623 For a subprogram whose calling convention is Intrinsic,
2624 or for a package,
2625 the implementation need not generate an out-of-line
2626 piece of code for it.
2627 @end{Reason}
2628
2629 An implementation should support Address clauses for
2630 imported subprograms.
2631
2632 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]}
2633 @ChgDeleted{Version=[2],Text=[Objects (including subcomponents) that are
2634 aliased or of a by-reference type
2635 should be allocated on storage element boundaries.]}
2636 @Comment{There is a now a blanket permission to this effect}
2637 @begin{Reason}
2638 @ChgRef{Version=[2],Kind=[Deleted]}
2639 @ChgDeleted{Version=[2],Text=[This is necessary for the Address attribute to be
2640 useful (since First_Bit and Last_Bit apply only to components). Implementations
2641 generally need to do this anyway, for tasking to work properly.]}
2642 @end{Reason}
2643
2644 If the Address of an object is specified,
2645 or it is imported or exported,
2646 then the implementation should not perform optimizations based on
2647 assumptions of no aliases.
2648 @end{Itemize}
2649 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2650 Text=[The recommended level of support for the Address attribute should be
2651 followed.]}]}
2652 @end{ImplAdvice}
2653
2654 @begin{Notes}
2655 The specification of a link name @Chg{Version=[3],New=[with the Link_Name
2656 aspect],Old=[in a @nt{pragma} Export]}
2657 (see @RefSecNum{Interfacing Aspects})
2658 for a subprogram or object is an alternative to explicit
2659 specification of its link-time address, allowing a link-time directive
2660 to place the subprogram or object within memory.
2661
2662 The rules for the Size attribute imply,
2663 for an aliased object X, that if X'Size = Storage_Unit,
2664 then X'Address points at a storage element containing all
2665 of the bits of X, and only the bits of X.
2666 @end{Notes}
2667
2668 @begin{DiffWord83}
2669 The intended meaning of the various attributes,
2670 and their @nt{attribute_definition_clause}s,
2671 is more explicit.
2672
2673 The @ntf{address_clause} has been renamed to @nt{at_clause} and moved
2674 to @RefSec{Obsolescent Features}.
2675 One can use an Address clause
2676 (@lquotes@;for T'Address @key[use] ...;@rquotes@;)
2677 instead.
2678
2679 The attributes defined in RM83-13.7.3 are moved to
2680 @RefSecNum{Numerics},
2681 @RefSecNum{Attributes of Floating Point Types}, and
2682 @RefSecNum{Attributes of Fixed Point Types}.
2683 @end{DiffWord83}
2684
2685 @begin{DiffWord2005}
2686 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1]}
2687 @ChgAdded{Version=[3],Text=[Defined that the names of aspects are the same as
2688 the name of the attribute; that gives a name to use in @nt{aspect_specification}s
2689 (see @RefSecNum{Aspect Specifications}).]}
2690 @end{DiffWord2005}
2691
2692 @begin{MetaRules}
2693 By default, the Alignment of a subtype should
2694 reflect the @lquotes@;natural@rquotes@; alignment for objects of the
2695 subtype on the machine.
2696 The Alignment, whether specified or default,
2697 should be known at compile time, even though
2698 Addresses are generally not known at compile
2699 time.
2700 (The generated code should never need to check
2701 at run time the number of zero bits at the end
2702 of an address to determine an alignment).
2703
2704 There are two symmetric purposes of Alignment clauses, depending on
2705 whether or not the implementation has control over object
2706 allocation.
2707 If the implementation allocates an object,
2708 the implementation should ensure that
2709 the Address and Alignment are consistent with
2710 each other.
2711 If something outside the implementation allocates an
2712 object, the implementation should be allowed to
2713 assume that the Address and Alignment are
2714 consistent, but should not assume stricter alignments
2715 than that.
2716 @end{MetaRules}
2717
2718 @begin{StaticSem}
2719 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
2720 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
2721 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
2722 @Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes @Chg{Version=[2],New=[an],
2723 Old=[a subtype or]} object]}:
2724 @begin{Description}
2725 @ChgAttribute{Version=[2], Kind=[Revised], ChginAnnex=[T], Leading=[F],
2726 Prefix=<X>, AttrName=<Alignment>, ARef=[AI95-00291-02], InitialVersion=[0],
2727 Text=[@Chg{Version=[2],New=[The value of this attribute is of type
2728 @i{universal_integer}, and nonnegative; zero means that the object is not
2729 necessarily aligned on a storage element boundary. If X'Alignment is not
2730 zero, then X is aligned on a storage unit boundary and X'Address],
2731 Old=[The Address of an object that is allocated under
2732 control of the implementation]} is an integral multiple of
2733 @Chg{Version=[2],New=[X'Alignment],Old=[the Alignment of the object]}
2734 (that is, the Address modulo the Alignment is zero).@Chg{Version=[2],
2735 New=[],Old=[The offset of a record component is a multiple of the
2736 Alignment of the component.
2737 For an object that is not allocated under control of
2738 the implementation
2739 (that is, one that is imported,
2740 that is allocated by a user-defined allocator,
2741 whose Address has been specified,
2742 or is designated by an access value returned by an
2743 instance of Unchecked_Conversion),
2744 the implementation may assume that the Address is
2745 an integral multiple of its Alignment.
2746 The implementation shall not assume a stricter alignment.]}
2747
2748 @Comment{Deleted below causes trouble in the generated text for attributes,
2749 but no fix appears to be possible. And the trouble is much worse in the
2750 RTF version than the HTML version, so for now we're making a hand fix.}
2751 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]}
2752 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The value of this attribute
2753 is of type @i{universal_integer}, and nonnegative;
2754 zero means that the object is not necessarily
2755 aligned on a storage element boundary.]}]}@Comment{End X'Alignment}
2756 @EndPrefixType{}
2757 @begin{Ramification}
2758 The Alignment is passed by an @nt{allocator} to the Allocate operation;
2759 the implementation has to choose a value such that if the address
2760 returned by Allocate is aligned as requested,
2761 the generated code can correctly access the object.
2762
2763 The above mention of @lquotes@;modulo@rquotes@; is referring to the "@key[mod]"
2764 operator declared in System.Storage_Elements;
2765 if X @key[mod] N = 0, then X is by definition aligned on an
2766 N-storage-element boundary.
2767 @end{Ramification}
2768
2769 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
2770 @NoPrefix@Chg{Version=[2],New=[@PDefn2{Term=[specifiable], Sec=(of Alignment for objects)}],
2771 Old=[@PDefn2{Term=[specifiable], Sec=(of Alignment for first subtypes and objects)}]}
2772 @Defn{Alignment clause}
2773 Alignment may be specified for@Chg{Version=[2],New=[],Old=[ first subtypes and]}
2774 @Redundant[stand-alone] objects via an @nt{attribute_@!definition_@!clause};
2775 the expression of such a clause shall be static, and its value
2776 nonnegative.@Chg{Version=[2],New=[],Old=[If the Alignment of a subtype is
2777 specified, then the Alignment of an object of the subtype is at least as
2778 strict, unless the object's Alignment is also specified.
2779 The Alignment of an object created by an allocator is that of the
2780 designated subtype.@Chg{Version=[3],New=[@AspectDefn{Alignment (object)}],Old=[]}]}
2781
2782 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Alignment (object)],
2783 Text=[@ChgAdded{Version=[3],Text=[Alignment of an object.]}]}
2784
2785 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00247-01]}
2786 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[If an Alignment is specified
2787 for a composite subtype or object, this
2788 Alignment shall be equal to the least common multiple of any
2789 specified Alignments of the subcomponent subtypes, or an integer
2790 multiple thereof.]}
2791 @end{Description}
2792
2793 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2794 @ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],
2795 Text=[For @PrefixType{every subtype S}:]}
2796 @begin{Description}
2797 @ChgAttribute{Version=[2], Kind=[Added], ChginAnnex=[T], Leading=[F],
2798 Prefix=<S>, AttrName=<Alignment>, ARef=[AI95-00291-02], InitialVersion=[2],
2799 Text=[@Chg{Version=[2],New=[The value of this attribute is of type
2800 @i{universal_integer}, and nonnegative.],Old=[]}
2801
2802 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02],ARef=[AI95-00291-02]}
2803 @ChgAdded{Version=[2],NoPrefix=[T], Text=[For an object X of subtype S,
2804 if S'Alignment is not zero, then X'Alignment is a nonzero integral multiple
2805 of S'Alignment unless specified otherwise by a representation
2806 item.]}]}@Comment{End S'Alignment}
2807
2808 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2809 @ChgAdded{Version=[2],NoPrefix=[T], Text=[@PDefn2{Term=[specifiable], Sec=(of Alignment for first subtypes)}
2810 @Defn{Alignment clause}
2811 Alignment may be specified for first subtypes via an
2812 @nt{attribute_@!definition_@!clause};
2813 the expression of such a clause shall be static, and its value
2814 nonnegative.@Chg{Version=[3],New=[@AspectDefn{Alignment (subtype)}],Old=[]}]}
2815
2816 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Alignment (subtype)],
2817 Text=[@ChgAdded{Version=[3],Text=[Alignment of a subtype.]}]}
2818
2819 @end{Description}
2820
2821 @end{StaticSem}
2822
2823 @begin{Erron}
2824 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2825 Program execution is erroneous if an Address clause is given that
2826 conflicts with the Alignment.
2827 @begin{Ramification}
2828 The user has to either give an Alignment clause also,
2829 or else know what Alignment the implementation will choose by default.
2830 @end{Ramification}
2831
2832 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02],ARef=[AI95-00291-02]}
2833 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2834 @Chg{Version=[2],New=[For],Old=[If the Alignment is specified for]} an
2835 object that is not allocated under control of the implementation,
2836 execution is erroneous if the object is not aligned according to
2837 @Chg{Version=[2],New=[its],Old=[the]} Alignment.
2838
2839 @end{Erron}
2840
2841 @begin{ImplAdvice}
2842 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0116-1]}
2843 @ChgAdded{Version=[3],Text=[For any tagged specific subtype @i<S>,
2844 @i<S>'Class'Alignment should equal @i<S>'Alignment.]}
2845
2846 @begin{Reason}
2847 @ChgRef{Version=[3],Kind=[AddedNormal]}
2848 @ChgAdded{Version=[3],Text=[A tagged object should never be less aligned than
2849 the alignment of the type of its view, so for a class-wide type T'Class, the
2850 alignment should be no greater than that of any type covered by T'Class. If the
2851 implementation only supports alignments that are required by the recommended
2852 level of support (and this is most likely), then the alignment of any covered
2853 type has to be the same or greater than that of T @em which leaves the only
2854 reasonable value of T'Class'Alignment being T'Alignment. Thus we recommend this,
2855 but don't require it so that in the unlikely case that the implementation does
2856 support smaller alignments for covered types, it can select a smaller value
2857 for T'Class'Alignment.]}
2858 @end{Reason}
2859 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
2860 Text=[For any tagged specific subtype @i<S>,
2861 @i<S>'Class'Alignment should equal @i<S>'Alignment.]}]}
2862
2863 @PDefn2{Term=[recommended level of support], Sec=(Alignment attribute
2864 for subtypes)}
2865 @Leading@;The recommended level of support for the Alignment attribute for
2866 subtypes is:
2867 @begin{Itemize}
2868 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
2869 An implementation should support @Chg{Version=[2],New=[an Alignment clause
2870 for a discrete type, fixed point type, record type, or
2871 array type, specifying an Alignment value that is zero or
2872 a power of two],Old=[specified Alignments that are factors and multiples of
2873 the number of storage elements per word]}, subject to the following:
2874
2875 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
2876 An implementation need not support
2877 @Chg{Version=[2], New=[an Alignment clause for a signed
2878 integer type specifying an Alignment greater than the largest
2879 Alignment value that is ever chosen by default by the implementation
2880 for any signed integer type. A corresponding limitation may be
2881 imposed for modular integer types, fixed point types, enumeration types,
2882 record types, and array types],Old=[specified Alignments for combinations
2883 of Sizes and Alignments that cannot be easily loaded and
2884 stored by available machine instructions]}.
2885
2886 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
2887 An implementation need not support
2888 @Chg{Version=[2],New=[a nonconfirming Alignment clause which could enable the
2889 creation of an object of an elementary type which cannot be easily loaded and
2890 stored by available machine instructions.],
2891 Old=[specified Alignments that are greater than the maximum
2892 Alignment the implementation ever returns
2893 by default.]}
2894
2895 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2896 @ChgAdded{Version=[2],Text=[An implementation need not support an
2897 Alignment specified for a derived tagged type which is not a multiple of the
2898 Alignment of the parent type. An implementation need not support a
2899 nonconfirming Alignment specified for a derived untagged by-reference type.]}
2900 @begin{Ramification}
2901 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
2902 @ChgAdded{Version=[2],Text=[There is no recommendation to support any
2903 nonconfirming Alignment clauses for types not mentioned above.
2904 Remember that
2905 @RefSecNum{Operational and Representation Aspects} requires support for
2906 confirming Alignment clauses for all types.]}
2907 @end{Ramification}
2908 @begin{ImplNote}
2909 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0116-1]}
2910 @ChgAdded{Version=[3],Text=[An implementation that tries to support other
2911 alignments for derived tagged types will need to allow inherited subprograms
2912 to be passed objects that are less aligned than expected by the parent
2913 subprogram and type. This is unlikely to work if alignment has any effect on
2914 code selection. Similar issues arise for untagged derived types whose
2915 parameters are passed by reference.]}
2916 @end{ImplNote}
2917 @end{Itemize}
2918
2919 @Leading@PDefn2{Term=[recommended level of support], Sec=(Alignment attribute
2920 for objects)}
2921 The recommended level of support for the Alignment attribute for
2922 objects is:
2923 @begin{Itemize}
2924 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]}
2925 @ChgDeleted{Version=[2],Text=[Same as above, for subtypes, but in addition:]}
2926
2927 For stand-alone library-level objects of statically constrained
2928 subtypes, the implementation should support all Alignments
2929 supported by the target linker. For example, page alignment
2930 is likely to be supported for such objects, but not for subtypes.
2931
2932 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2933 @ChgAdded{Version=[2],Text=[For other objects, an implementation should at
2934 least support the alignments supported for their
2935 subtype, subject to the following:]}
2936
2937 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2938 @ChgAdded{Version=[2],Text=[An implementation need not support Alignments
2939 specified for objects of a by-reference type or for objects of types containing
2940 aliased subcomponents if the specified Alignment is not a multiple of the
2941 Alignment of the subtype of the object.]}
2942 @end{Itemize}
2943 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2944 Text=[The recommended level of support for the Alignment attribute should be
2945 followed.]}]}
2946 @end{ImplAdvice}
2947
2948 @begin{Notes}
2949 Alignment is a subtype-specific attribute.
2950
2951 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00247-01]}
2952 @ChgDeleted{Version=[2],Text=[The Alignment of a composite object is always
2953 equal to the least common multiple of the Alignments of its components, or a
2954 multiple thereof.]}
2955 @begin{Discussion}
2956 @ChgRef{Version=[2],Kind=[Deleted]}
2957 @ChgDeleted{Version=[2],Text=[For default Alignments, this follows from the
2958 semantics of Alignment. For specified Alignments, it follows from a
2959 @LegalityName stated above.]}
2960 @end{Discussion}
2961
2962 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1],ARef=[AI05-0269-1]}
2963 A @nt{component_clause}, Component_Size clause, or
2964 @Chg{Version=[3],New=[specifying the],Old=[a @nt{pragma}]} Pack
2965 @Chg{Version=[3],New=[aspect as True ],Old=[]}can override a specified
2966 Alignment.
2967 @begin{Discussion}
2968 Most objects are allocated by the implementation; for these, the
2969 implementation obeys the Alignment. The implementation is of course
2970 allowed to make an object @i{more} aligned than its Alignment requires
2971 @em an object whose Alignment is 4 might just happen to land at an
2972 address that's a multiple of 4096.
2973 For formal parameters, the implementation might
2974 want to force an Alignment stricter than the parameter's subtype.
2975 For example, on some systems, it is customary to always align
2976 parameters to 4 storage elements.
2977
2978 Hence, one might initially assume that the implementation could
2979 evilly make all Alignments 1 by default, even though integers, say,
2980 are normally aligned on a 4-storage-element boundary. However, the
2981 implementation cannot get away with that @em if the Alignment is 1,
2982 the generated code cannot assume an Alignment of 4, at least not for
2983 objects allocated outside the control of the implementation.
2984
2985 Of course implementations can assume anything they can prove, but
2986 typically an implementation will be unable to prove much about the
2987 alignment of, say, an imported object. Furthermore, the information
2988 about where an address @lquotes@;came from@rquotes@; can be lost to the compiler due to
2989 separate compilation.
2990
2991 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
2992 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2993 The Alignment of an object that is a component of a packed
2994 composite object will usually be 0, to indicate that the component is
2995 not necessarily aligned on a storage element boundary.
2996 For a subtype, an Alignment of 0 means that objects of the subtype are
2997 not normally aligned on a storage element boundary at all.
2998 For example, an implementation might choose to make Component_Size be
2999 @Chg{Version=[2],New=[1],Old=[0]}
3000 for an array of Booleans, even
3001 when @Chg{Version=[3],New=[the],Old=[@nt{pragma}]} Pack
3002 @Chg{Version=[3],New=[aspect ],Old=[]}has not been
3003 specified for the array.
3004 In this case, Boolean'Alignment would be 0.
3005 (In the presence of tasking, this would in general be feasible only on a
3006 machine that had atomic test-bit and set-bit instructions.)
3007
3008 If the machine has no particular natural alignments, then all subtype
3009 Alignments will probably be 1 by default.
3010
3011 Specifying an Alignment of 0 in an @nt{attribute_definition_clause} does
3012 not require the implementation to do anything (except return 0 when the
3013 Alignment is queried).
3014 However, it might be taken as advice on some implementations.
3015
3016 It is an error for an Address clause to disobey the object's Alignment.
3017 The error cannot be detected at compile time, in general, because the
3018 Address is not necessarily known at compile time (and is almost
3019 certainly not static). We do not require a run-time check, since
3020 efficiency seems paramount here, and Address clauses are treading on
3021 thin ice anyway. Hence, this misuse of Address clauses is just like any
3022 other misuse of Address clauses @em it's erroneous.
3023
3024 A type extension can have a stricter Alignment than its parent.
3025 This can happen, for example, if the Alignment of the parent is 4,
3026 but the extension contains a component with Alignment 8.
3027 The Alignment of a class-wide type or object will have to be the
3028 maximum possible Alignment of any extension.
3029
3030 The recommended level of support for the Alignment attribute is
3031 intended to reflect a minimum useful set of capabilities. An
3032 implementation can assume that all Alignments are multiples of each
3033 other @em 1, 2, 4, and 8 might be the only supported Alignments for
3034 subtypes. An Alignment of 3 or 6 is unlikely to be useful.
3035 For objects that can be allocated statically, we recommend that
3036 the implementation support larger alignments, such as 4096. We do
3037 not recommend such large alignments for subtypes, because the maximum
3038 subtype alignment will also have to be used as the alignment of stack
3039 frames, heap objects, and class-wide objects. Similarly, we do not
3040 recommend such large alignments for stack-allocated objects.
3041
3042 If the maximum default Alignment is 8
3043 (say, Long_Float'Alignment = 8),
3044 then the implementation can refuse to accept stricter alignments
3045 for subtypes. This simplifies the generated code, since the compiler
3046 can align the stack and class-wide types to this maximum without a
3047 substantial waste of space (or time).
3048
3049 Note that the recommended level of support takes into account
3050 interactions between Size and Alignment. For example, on a 32-bit
3051 machine with 8-bit storage elements, where load and store
3052 instructions have to be aligned according to the size of the thing
3053 being loaded or stored, the implementation might accept an Alignment
3054 of 1 if the Size is 8, but might reject an Alignment of 1 if the Size
3055 is 32. On a machine where unaligned loads and stores are merely
3056 inefficient (as opposed to causing hardware traps),
3057 we would expect an Alignment of 1 to be supported for any Size.
3058 @end{Discussion}
3059 @end{Notes}
3060
3061 @begin{DiffWord83}
3062 The nonnegative part is missing from RM83
3063 (for @nt{mod_clause}s, nee @ntf{alignment_clause}s,
3064 which are an obsolete version of Alignment clauses).
3065 @end{DiffWord83}
3066
3067 @begin{StaticSem}
3068 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3069 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
3070 @Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes an object]}:
3071 @begin{Description}
3072 @Attribute{Prefix=<X>, AttrName=<Size>,
3073 Text=<Denotes the size in bits of
3074 the representation of the object.
3075 The value of this attribute is of the type
3076 @i{universal_integer}.>}
3077 @EndPrefixType{}
3078 @begin{Ramification}
3079 Note that Size is in bits even if Machine_Radix is 10.
3080 Each decimal digit (and the sign) is presumably represented
3081 as some number of bits.
3082 @end{Ramification}
3083
3084 @NoPrefix@PDefn2{Term=[specifiable], Sec=(of Size for stand-alone objects)}
3085 @Defn{Size clause}
3086 Size may be specified for @Redundant[stand-alone] objects
3087 via an @nt{attribute_definition_clause};
3088 the expression of such a clause shall be static and its
3089 value nonnegative.@Chg{Version=[3],New=[@AspectDefn{Size (object)}],Old=[]}
3090
3091 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Size (object)],
3092 Text=[@ChgAdded{Version=[3],Text=[Size in bits of an object.]}]}
3093
3094 @end{Description}
3095 @end{StaticSem}
3096
3097 @begin{ImplAdvice}
3098 @ChgNote{Moved from 13.9}
3099 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]}
3100 @ChgAdded{Version=[2],Text=[The size of an array object should not include
3101 its bounds.]}
3102 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
3103 Text=[The Size of an array object should not include its bounds.]}]}
3104
3105 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02],ARef=[AI95-00291-02]}
3106 @ChgDeleted{Version=[2],Type=[Leading],Text=[]}@Comment{A fake to get a conditional Leading}
3107 @PDefn2{Term=[recommended level of support], Sec=(Size attribute)}
3108 The recommended level of support for the Size attribute
3109 of objects is@Chg{Version=[2],New=[ the same as for subtypes (see below),
3110 except that only a confirming Size clause need be supported for an aliased
3111 elementary object.],Old=[:]}
3112 @begin{Itemize}
3113 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00051-02]}
3114 @ChgDeleted{Version=[2],Text=[A Size clause should be supported for an object
3115 if the specified Size is at least as large as its subtype's Size, and
3116 corresponds to a size in storage elements that is a multiple of the object's
3117 Alignment (if the Alignment is nonzero).]}
3118 @Comment{No ImplDef summary here; there is no reason to separately mention it}
3119 @end{Itemize}
3120 @end{ImplAdvice}
3121
3122 @begin{StaticSem}
3123 @Leading@Keepnext@;For @PrefixType{every subtype S}:
3124 @begin{Description}
3125 @AttributeLeading{Prefix=<S>, AttrName=<Size>,
3126 Text=<If S is definite,
3127 denotes the size @Redundant{(in bits)}
3128 that the implementation would choose for
3129 the following objects of subtype S:
3130 @begin{Itemize}
3131 A record component of subtype S
3132 when the record type is packed.
3133
3134 The formal parameter of an instance of Unchecked_Conversion
3135 that converts from subtype S to some other subtype.
3136 @end{Itemize}
3137
3138 @NoPrefix@;If S is indefinite,
3139 the meaning is implementation defined.
3140 The value of this attribute is of the type
3141 @i{universal_integer}.>}
3142 @PDefn2{Term=[specifiable], Sec=(of Size for first subtypes)}
3143 @Defn{Size clause}
3144 The Size of an object is at least as large as that of its subtype,
3145 unless the object's Size is determined by a Size clause,
3146 a component_clause, or a Component_Size clause.
3147 Size may be specified for first subtypes
3148 via an @nt{attribute_@!definition_@!clause};
3149 the expression of such a clause shall be static
3150 and its value nonnegative.@Chg{Version=[3],New=[@AspectDefn{Size (subtype)}],Old=[]}
3151 @ImplDef{The meaning of Size for indefinite subtypes.}
3152 @begin{Reason}
3153 @Leading@;The effects of specifying the Size of a subtype are:
3154 @begin{Itemize}
3155 Unchecked_Conversion works in a predictable manner.
3156
3157 A composite type cannot be packed so tightly as to override
3158 the specified Size of a component's subtype.
3159
3160 Assuming the @ImplAdviceName is obeyed,
3161 if the specified Size allows independent addressability,
3162 then the Size of certain objects of the subtype
3163 should be equal to the subtype's Size.
3164 This applies to stand-alone objects and to components
3165 (unless a @nt{component_clause} or a Component_Size clause applies).
3166 @end{Itemize}
3167
3168 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3169 A @nt{component_clause} or a Component_Size clause can cause an object
3170 to be smaller than its subtype's specified size.
3171 @Chg{Version=[3],New=[The aspect],Old=[A @nt{pragma}]}
3172 Pack cannot; if a component subtype's size is specified,
3173 this limits how tightly the composite object can be packed.
3174
3175 The Size of a class-wide (tagged) subtype is unspecified,
3176 because it's not clear what it should mean;
3177 it should certainly not depend on all of the descendants that happen
3178 to exist in a given program.
3179 Note that this cannot be detected at compile time,
3180 because in a generic unit, it is not necessarily known
3181 whether a given subtype is class-wide.
3182 It might raise an exception on some implementations.
3183 @end{Reason}
3184 @begin{Ramification}
3185 @Leading@;A Size clause for a numeric subtype need not
3186 affect the underlying numeric type.
3187 For example, if I say:
3188 @begin{Example}
3189 @key[type] S @key[is] @key[range] 1..2;
3190 @key[for] S'Size @key[use] 64;
3191 @end{Example}
3192
3193 I am not guaranteed that S'Base'Last >= 2**63@en@;1,
3194 nor that intermediate results will be represented in 64 bits.
3195 @end{Ramification}
3196 @begin{Reason}
3197 There is no need to complicate implementations for this sort of
3198 thing, because the right way to affect the base range of a type
3199 is to use the normal way of declaring the base range:
3200 @begin{Example}
3201 @key[type] Big @key[is] @key[range] -2**63 .. 2**63 - 1;
3202 @key[subtype] Small @key[is] Big @key[range] 1..1000;
3203 @end{Example}
3204 @end{Reason}
3205 @begin{Ramification}
3206 The Size of a large unconstrained subtype (e.g. String'Size)
3207 is likely to raise Constraint_Error,
3208 since it is a nonstatic expression of type @i{universal_integer}
3209 that might overflow the largest signed integer type.
3210 There is no requirement that the largest integer type be able to
3211 represent the size in bits of the largest possible object.
3212 @end{Ramification}
3213
3214 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Size (subtype)],
3215 Text=[@ChgAdded{Version=[3],Text=[Size in bits of a subtype.]}]}
3216
3217 @end{Description}
3218 @EndPrefixType{}
3219 @end{StaticSem}
3220
3221 @begin{ImplReq}
3222 In an implementation, Boolean'Size shall be 1.
3223 @end{ImplReq}
3224
3225 @begin{ImplAdvice}
3226 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
3227 @Leading@;If the Size of a subtype @Chg{Version=[2],New=[],Old=[is specified,
3228 and ]}allows for efficient independent addressability
3229 (see @RefSecNum{Shared Variables}) on the target architecture,
3230 then the Size of the following objects of the subtype should equal the
3231 Size of the subtype:
3232 @begin{Itemize}
3233 Aliased objects (including components).
3234
3235 Unaliased components, unless the Size of the
3236 component is determined by a @nt{component_clause} or Component_Size
3237 clause.
3238 @end{Itemize}
3239 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
3240 Text=[If the Size of a subtype allows for efficient independent
3241 addressability, then the Size of most objects of the subtype should
3242 equal the Size of the subtype.]}]}
3243 @begin{Ramification}
3244 Thus, on a typical 32-bit machine,
3245 @lquotes@;@key[for] S'Size @key[use] 32;@rquotes@;
3246 will guarantee that aliased objects of subtype S,
3247 and components whose subtype is S, will have Size
3248 = 32 (assuming the implementation chooses to obey this @ImplAdviceTitle).
3249 On the other hand, if one writes,
3250 @lquotes@;@key[for] S2'Size @key[use] 5;@rquotes@;
3251 then stand-alone objects of subtype S2 will typically have their Size
3252 rounded up to ensure independent addressability.
3253
3254 Note that @lquotes@;@key[for] S'Size @key[use] 32;@rquotes@;
3255 does not cause things like formal parameters to have Size = 32 @em
3256 the implementation is allowed to make all parameters be at least 64
3257 bits, for example.
3258
3259 Note that
3260 @lquotes@;@key[for] S2'Size @key[use] 5;@rquotes@;
3261 requires record components whose subtype is S2 to be exactly 5 bits
3262 if the record type is packed.
3263 The same is not true of array components;
3264 their Size may be rounded up to the nearest factor of the word size.
3265 @end{Ramification}
3266 @begin{ImplNote}
3267 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
3268 @Defn{gaps}
3269 On most machines, arrays don't contain gaps between @Chg{Version=[2],
3270 New=[elementary ],Old=[]}components;
3271 if the Component_Size is greater than the Size of the component subtype,
3272 the extra bits are generally considered part of each component,
3273 rather than gaps between components.
3274 On the other hand,
3275 a record might contain gaps between @Chg{Version=[2],
3276 New=[elementary ],Old=[]}components,
3277 depending on what sorts of loads, stores, and masking operations
3278 are generally done by the generated code.
3279
3280 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
3281 For an array,
3282 any extra bits stored for each @Chg{Version=[2],
3283 New=[elementary ],Old=[]}component will generally be part
3284 of the component @em the whole point of storing extra bits is to
3285 make loads and stores more efficient by avoiding the need to mask out
3286 extra bits.
3287 The PDP-10 is one counter-example;
3288 since the hardware supports byte strings with a gap at the end of
3289 each word,
3290 one would want to pack in that manner.
3291 @end{ImplNote}
3292
3293 A Size clause on a composite subtype should not affect
3294 the internal layout of components.
3295 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
3296 Text=[A Size clause on a composite subtype should not affect
3297 the internal layout of components.]}]}
3298 @begin{Reason}
3299 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3300 That's what Pack @Chg{Version=[3],New=[aspects],Old=[@nt{pragma}s]},
3301 @nt{record_representation_clause}s,
3302 and Component_Size clauses are for.
3303 @end{Reason}
3304
3305 @Leading@PDefn2{Term=[recommended level of support], Sec=(Size attribute)}
3306 The recommended level of support for the Size attribute
3307 of subtypes is:
3308 @begin{Itemize}
3309
3310 The Size (if not specified) of a static discrete or fixed point subtype
3311 should be the number of bits needed to represent each value belonging to
3312 the subtype using an unbiased representation,
3313 leaving space for a sign bit only if the subtype contains negative
3314 values.
3315 If such a subtype is a first subtype,
3316 then an implementation should support a specified Size for it that
3317 reflects this representation.
3318
3319 @begin{ImplNote}
3320 This applies to static enumeration subtypes,
3321 using the internal codes used to represent the values.
3322
3323 For a two's-complement machine, this implies that
3324 for a static signed integer subtype S,
3325 if all values of S are in the range 0 .. 2@+{@i{n}}@en@;1,
3326 or all values of S are in the range @en@;2@+{@i{n@en@;1}} .. 2@+{@i{n@en@;1}}@en@;1,
3327 for some @i{n} less than or equal to the word size,
3328 then S'Size should be <= the smallest such @i{n}.
3329 For a one's-complement machine,
3330 it is the same except that in the second range,
3331 the lower bound @lquotes@;@en@;2@+{@i{n@en@;1}}@rquotes@; is replaced by @lquotes@;@en@;2@+{@i{n@en@;1}}+1@rquotes@;.
3332
3333
3334 If an integer subtype (whether signed or unsigned)
3335 contains no negative values, the Size should not include space
3336 for a sign bit.
3337
3338
3339 Typically, the implementation will choose to make the Size of a
3340 subtype be exactly the smallest such @i{n}.
3341 However, it might, for example, choose a biased representation,
3342 in which case it could choose a smaller value.
3343
3344 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3345 On most machines, it is in general not a good idea to pack (parts of)
3346 multiple stand-alone objects into the same storage element,
3347 because (1) it usually doesn't save much space,
3348 and (2) it requires locking to prevent tasks from interfering with each
3349 other, since separate stand-alone objects are independently
3350 addressable.
3351 Therefore, if S'Size = 2
3352 on a machine with 8-bit storage elements,
3353 the size of a stand-alone object of subtype S will probably not be 2.
3354 It might, for example, be 8, 16 or 32, depending on the availability
3355 and efficiency of various machine instructions.
3356 The same applies to components of composite types,
3357 unless @Chg{Version=[3],New=[Pack],Old=[packing]},
3358 Component_Size, or record layout is specified.
3359
3360 For an unconstrained discriminated object,
3361 if the implementation allocates the maximum
3362 possible size,
3363 then the Size attribute should return that maximum
3364 possible size.
3365 @end{ImplNote}
3366 @begin{Ramification}
3367 The Size of an object X is not usually the same as that of
3368 its subtype S.
3369 If X is a stand-alone object or a parameter, for example,
3370 most implementations will round X'Size up to a storage
3371 element boundary, or more, so X'Size might be greater than S'Size.
3372 On the other hand,
3373 X'Size cannot be less than S'Size, even
3374 if the implementation can prove, for example,
3375 that the range of values actually taken on by X during execution
3376 is smaller than the range of S.
3377
3378 For example, if S is a first integer subtype whose range
3379 is 0..3, S'Size will be probably be 2 bits, and components of
3380 packed composite types of this subtype will be 2 bits
3381 (assuming Storage_Unit is a multiple of 2),
3382 but stand-alone objects and parameters will probably
3383 not have a size of 2 bits; they might be rounded up to
3384 32 bits, for example.
3385 On the other hand, Unchecked_Conversion will use the 2-bit size,
3386 even when converting a stand-alone object,
3387 as one would expect.
3388
3389 Another reason for making the Size of an object bigger than
3390 its subtype's Size is to support the run-time detection of
3391 uninitialized variables.
3392 @PDefn{uninitialized variables}
3393 The implementation might add an extra value to a discrete subtype
3394 that represents the uninitialized state,
3395 and check for this value on use.
3396 In some cases, the extra value will require an extra bit in the
3397 representation of the object.
3398 Such detection is not required by the language.
3399 If it is provided, the implementation has to be able to turn it off.
3400 For example, if the programmer gives a
3401 @nt{record_representation_clause} or Component_Size clause that makes
3402 a component too small to allow the extra bit,
3403 then the implementation will not be able to perform the checking
3404 (not using this method, anyway).
3405
3406 @Leading@;The fact that the size of an object is not necessarily the same
3407 as its subtype can be confusing:
3408 @begin{Example}
3409 @key[type] Device_Register @key[is] @key[range] 0..2**8 - 1;
3410 @key[for] Device_Register'Size @key[use] 8; --@RI{ Confusing!}
3411 My_Device : Device_Register;
3412 @key[for] My_Device'Address @key[use] To_Address(16#FF00#);
3413 @end{Example}
3414
3415 The programmer might think that My_Device'Size is 8,
3416 and that My_Device'Address points at an 8-bit location.
3417 However, this is not true.
3418 In Ada 83 (and in Ada 95), My_Device'Size might well be 32,
3419 and My_Device'Address might well point at the high-order 8 bits of
3420 the 32-bit object, which are always all zero bits.
3421 If My_Device'Address is passed to an assembly language subprogram,
3422 based on the programmer's assumption,
3423 the program will not work properly.
3424 @end{Ramification}
3425 @begin{Reason}
3426 It is not reasonable to require that an implementation allocate
3427 exactly 8 bits to all objects of subtype Device_Register.
3428 For example, in many run-time models, stand-alone objects
3429 and parameters are always aligned to a word boundary.
3430 Such run-time models are generally based on hardware considerations
3431 that are beyond the control of the implementer.
3432 (It is reasonable to require that an implementation allocate exactly
3433 8 bits to all components of subtype Device_Register, if packed.)
3434 @end{Reason}
3435 @begin{Ramification}
3436 @Leading@;The correct way to write the above code is like this:
3437 @begin{Example}
3438 @key[type] Device_Register @key[is] @key[range] 0..2**8 - 1;
3439 My_Device : Device_Register;
3440 @key[for] My_Device'Size @key[use] 8;
3441 @key[for] My_Device'Address @key[use] To_Address(16#FF00#);
3442 @end{Example}
3443
3444 If the implementation cannot accept 8-bit stand-alone objects,
3445 then this will be illegal.
3446 However, on a machine where an 8-bit device register exists,
3447 the implementation will probably be able to accept 8-bit stand-alone
3448 objects. Therefore, My_Device'Size will be 8,
3449 and My_Device'Address will point at those 8 bits,
3450 as desired.
3451
3452 If an object of subtype Device_Register is passed to a foreign
3453 language subprogram, it will be passed according to that subprogram's
3454 conventions. Most foreign language implementations have similar
3455 run-time model restrictions.
3456 For example, when passing to a C function,
3457 where the argument is of
3458 the C type char* (that is, pointer to char),
3459 the C compiler will generally expect a full word value,
3460 either on the stack, or in a register.
3461 It will @i{not} expect a single byte.
3462 Thus, Size clauses for subtypes really have nothing to do with
3463 passing parameters to foreign language subprograms.
3464 @end{Ramification}
3465
3466 For a subtype implemented with levels of indirection,
3467 the Size should include the size of the pointers,
3468 but not the size of what they point at.
3469 @begin{Ramification}
3470 For example, if a task object is represented as a pointer to some
3471 information (including a task stack), then the size of the object
3472 should be the size of the pointer.
3473 The Storage_Size, on the other hand,
3474 should include the size of the stack.
3475 @end{Ramification}
3476
3477 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]}
3478 @ChgAdded{Version=[2],Type=[Leading],Text=[An implementation should support a
3479 Size clause for a discrete type, fixed point type, record type, or array type,
3480 subject to the following:]}
3481 @begin{InnerItemize}
3482
3483 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]}
3484 @ChgAdded{Version=[2],Text=[An implementation need not support a Size clause
3485 for a signed integer type specifying a Size greater than that of the largest
3486 signed integer type supported by the implementation in the absence of a size
3487 clause (that is, when the size is chosen by default). A corresponding
3488 limitation may be imposed for modular integer types, fixed point types,
3489 enumeration types, record types, and array types.]}
3490
3491 @begin{Discussion}
3492 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-02]}
3493 @ChgAdded{Version=[2],Text=[Note that the @lquotes@;corresponding
3494 limitation@rquotes for a record or array type implies that an implementation
3495 may impose some reasonable maximum size for records and arrays (e.g. 2**32
3496 bits), which is an upper bound (@lquotes@;capacity@rquotes limit) on the
3497 size, whether chosen by default or by being specified by the user. The
3498 largest size supported for records need not be the same as the largest
3499 size supported for arrays.]}
3500 @end{Discussion}
3501
3502 @begin{Ramification}
3503 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0155-1]}
3504 @ChgAdded{Version=[3],Text=[Only Size clauses with a size greater than or
3505 equal to the Size that would be chosen by default may be safely presumed to be
3506 supported on nonstatic elementary subtypes. Implementations may choose to
3507 support smaller sizes, but only if the Size allows any value of the subtype to
3508 be represented, for any possible value of the bounds.]}
3509 @end{Ramification}
3510
3511 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3512 @ChgAdded{Version=[2],Text=[A nonconfirming size clause for the first subtype
3513 of a derived untagged by-reference type need not be supported.]}
3514 @end{InnerItemize}
3515 @end{Itemize}
3516 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3517 Text=[The recommended level of support for the Size attribute should be
3518 followed.]}]}
3519 @begin{Ramification}
3520 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
3521 @ChgAdded{Version=[2],Text=[There is no recommendation to support any
3522 nonconfirming Size clauses for types not mentioned above.
3523 Remember that
3524 @RefSecNum{Operational and Representation Aspects} requires support for
3525 confirming Size clauses for all types.]}
3526 @end{Ramification}
3527 @end{ImplAdvice}
3528
3529 @begin{Notes}
3530 Size is a subtype-specific attribute.
3531
3532 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3533 A @nt{component_clause} or Component_Size clause
3534 can override a specified Size.
3535 @Chg{Version=[3],New=[Aspect],Old=[A @nt{pragma}]} Pack cannot.
3536 @end{Notes}
3537
3538 @begin{Inconsistent83}
3539 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00114-01]}
3540 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 83}We specify
3541 the meaning of Size in much more
3542 detail than Ada 83. This is not technically an inconsistency, but it is in
3543 practice, as most Ada 83 compilers use a different definition for Size than
3544 is required here. This should have been documented more explicitly during
3545 the Ada 9X process.]}
3546 @end{Inconsistent83}
3547
3548 @begin{DiffWord83}
3549 The requirement for a nonnegative value in a Size clause
3550 was not in RM83, but it's hard to see how it would make sense.
3551 For uniformity, we forbid negative sizes,
3552 rather than letting implementations define their meaning.
3553 @end{DiffWord83}
3554
3555 @begin{StaticSem}
3556 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3557 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
3558 @Chg{New=[@nt{prefix}],Old=[prefix]} T that denotes a task
3559 object @Redundant[(after any implicit dereference)]]}:
3560 @begin{Description}
3561 @ChgAttribute{Version=[3], Kind=[Revised], ChginAnnex=[F], Leading=[F],
3562 Prefix=<T>, AttrName=<Storage_Size>, ARef=[AI05-0229-1],
3563 Text=<Denotes the number of storage elements reserved for
3564 the task.
3565 The value of this attribute is of the type
3566 @i{universal_integer}.
3567 The Storage_Size includes the size of the task's stack,
3568 if any. The language does not specify whether or
3569 not it includes other storage associated with the task
3570 (such as the @lquotes@;task control block@rquotes@; used by some
3571 implementations.)>}
3572 If @Chg{Version=[3],New=[the aspect],Old=[a @nt{pragma}]} Storage_Size is
3573 @Chg{Version=[3],New=[specified for the type of the object],Old=[given]},
3574 the value of the Storage_Size attribute is at least
3575 the value @Chg{Version=[3],New=[determined by the aspect],Old=[specified
3576 in the @nt{pragma}]}.
3577 @EndPrefixType{}
3578 @begin{Ramification}
3579 The value of this attribute is never negative,
3580 since it is impossible to @lquotes@;reserve@rquotes@; a negative number
3581 of storage elements.
3582
3583 If the implementation chooses to allocate an initial amount of
3584 storage, and then increase this as needed,
3585 the Storage_Size cannot include the additional amounts
3586 (assuming the allocation of the additional amounts can raise
3587 Storage_Error); this is inherent in the meaning of @lquotes@;reserved.@rquotes@;
3588
3589 The implementation is allowed to allocate different amounts of
3590 storage for different tasks of the same subtype.
3591
3592 Storage_Size is also defined for access subtypes
3593 @em see @RefSecNum{Storage Management}.
3594 @end{Ramification}
3595 @end{Description}
3596 @end{StaticSem}
3597
3598 @begin{Intro}
3599 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI95-0229-1]}
3600 @redundant[@Chg{Version=[3],New=[Aspect],Old=[@IndexSeeAlso{Term=[Storage_Size clause],See=[pragma Storage_Size]}
3601 A @nt{pragma}]} Storage_Size specifies the amount of storage to be
3602 reserved for the execution of a task.]
3603 @end{Intro}
3604
3605 @begin{NotIso}
3606 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 62
3607 through 65 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
3608 should be deleted if the paragraphs are ever renumbered.}
3609 @end{NotIso}
3610
3611 @begin{Syntax}
3612 @begin{SyntaxText}
3613 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3614 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
3615 @nt{pragma} Storage_Size is as follows:]}
3616 @end{SyntaxText}
3617
3618 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3619 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
3620 Text=[@key{pragma} @prag(Storage_Size)(@Syn2{expression});]}>
3621
3622 @begin{SyntaxText}
3623 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3624 @ChgDeleted{Version=[3],Text=[A @nt{pragma} Storage_Size is allowed only
3625 immediately within a @nt{task_definition}.]}
3626 @end{SyntaxText}
3627 @end{Syntax}
3628
3629 @begin{Resolution}
3630 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3631 @ChgDeleted{Version=[3],Text=[@PDefn2{Term=[expected type],
3632 Sec=(Storage_Size pragma argument)}
3633 The @nt{expression} of a @nt<pragma> Storage_Size
3634 is expected to be of any integer type.]}
3635 @end{Resolution}
3636
3637 @begin{StaticSem}
3638 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1],ARef=[AI05-0269-1]}
3639 @ChgAdded{Version=[3],Type=[Leading],Text=[For a task type (including the
3640 anonymous type of a @nt{single_task_declaration}),
3641 the following language-defined representation aspect may be specified:]}
3642
3643 @begin{Description}
3644 @ChgRef{Version=[3],Kind=[Added]}
3645 @ChgAdded{Version=[3],Text=[Storage_Size@\The Storage_Size aspect is
3646 an @nt{expression}, which shall be of any integer
3647 type.@AspectDefn{Storage_Size (task)}]}
3648
3649 @begin{Honest}
3650 @ChgRef{Version=[3],Kind=[AddedNormal]}
3651 @ChgAdded{Version=[3],Text=[This definition somewhat conflicts with the
3652 "automatic" one for the obsolescent attribute Storage_Size (which can be
3653 specified). The only difference is where the given expression is evaluated.
3654 We intend for the above definition to supersede that "automatic"
3655 definition for this attribute.]}
3656 @end{Honest}
3657 @begin{Ramification}
3658 @ChgRef{Version=[3],Kind=[AddedNormal]}
3659 @ChgAdded{Version=[3],Text=[Note that the value of the Storage_Size aspect
3660 @i<is> an @nt{expression}; it is not the @i<value> of an @nt{expression}.
3661 The @nt{expression} is evaluated for each object of the type (see below).]}
3662 @end{Ramification}
3663
3664 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Storage_Size (task)],
3665 Text=[@ChgAdded{Version=[3],Text=[Size in storage elements reserved for a task
3666 type or single task object.]}]}
3667
3668 @end{Description}
3669 @end{StaticSem}
3670
3671 @begin{Legality}
3672 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
3673 @ChgAdded{Version=[3],Text=[The Storage_Size aspect shall not be specified for a
3674 task interface type.]}
3675 @end{Legality}
3676
3677 @begin{RunTime}
3678 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3679 @Chg{Version=[3],New=[When a task object is created, the @nt{expression}
3680 (if any) associated with the Storage_Size aspect of its
3681 type],Old=[A @nt<pragma> Storage_Size is elaborated when an object
3682 of the type defined by the immediately enclosing @nt<task_definition>
3683 is created.
3684 @PDefn2{Term=[elaboration],Sec=(Storage_Size pragma)}
3685 For the elaboration of a @nt<pragma> Storage_Size, the @nt<expression>]}
3686 is evaluated; the Storage_Size attribute of the newly created task object
3687 is at least the value of the @nt<expression>.
3688
3689 @begin{Ramification}
3690 The implementation is allowed to round up a specified Storage_Size
3691 amount.
3692 For example, if the implementation always allocates in
3693 chunks of 4096 bytes, the number 200 might be rounded
3694 up to 4096. Also, if the user specifies a negative
3695 number, the implementation has to normalize this to 0,
3696 or perhaps to a positive number.
3697
3698 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
3699 @ChgAdded{Version=[3],Text=[If the Storage_Size aspect is not specified for
3700 the type of the task object, the value of the Storage_Size attribute is
3701 unspecified.]}
3702 @end{Ramification}
3703
3704 @IndexCheck{Storage_Check}
3705 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
3706 At the point of task object creation, or upon task activation,
3707 Storage_Error is raised if there is insufficient free storage to
3708 accommodate the requested Storage_Size.
3709 @end{RunTime}
3710
3711 @begin{StaticSem}
3712 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3713 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
3714 @Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes an array subtype or
3715 array object @Redundant[(after any implicit dereference)]]}:
3716 @begin{Description}
3717 @Attribute{Prefix=<X>, AttrName=<Component_Size>,
3718 Text=<Denotes the size in bits of
3719 components of the type of X.
3720 The value of this attribute is of type @i{universal_integer}.>}
3721 @EndPrefixType{}
3722
3723 @NoPrefix@PDefn2{Term=[specifiable], Sec=(of Component_Size for
3724 array types)}@Defn{Component_Size clause}
3725 Component_Size may be specified for array types
3726 via an @nt{attribute_@!definition_@!clause};
3727 the expression of such a clause shall be static,
3728 and its value nonnegative.@Chg{Version=[3],New=[@AspectDefn{Component_Size}],Old=[]}
3729
3730 @begin{ImplNote}
3731 The intent is that the value of X'Component_Size is always nonnegative.
3732 If the array is stored @lquotes@;backwards@rquotes@; in memory
3733 (which might be caused by an implementation-defined pragma),
3734 X'Component_Size is still positive.
3735 @end{ImplNote}
3736 @begin{Ramification}
3737 For an array object A, A'Component_Size = A(I)'Size for any index I.
3738 @end{Ramification}
3739
3740 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Component_Size],
3741 Text=[@ChgAdded{Version=[3],Text=[Size in bits of a component of an array type.]}]}
3742
3743 @end{Description}
3744 @end{StaticSem}
3745
3746 @begin{ImplAdvice}
3747 @Leading@PDefn2{Term=[recommended level of support], Sec=(Component_Size attribute)}
3748 The recommended level of support for the Component_Size attribute is:
3749 @begin{Itemize}
3750 An implementation need not support specified Component_Sizes that
3751 are less than the Size of the component subtype.
3752
3753 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3754 An implementation should support specified Component_Sizes that
3755 are factors and multiples of the word size.
3756 For such Component_Sizes, the array should contain no gaps between
3757 components.
3758 For other Component_Sizes (if supported), the array should
3759 contain no gaps between components when
3760 @Chg{Version=[3],New=[Pack],Old=[packing]} is also specified;
3761 the implementation should forbid this combination in cases where it
3762 cannot support a no-gaps representation.
3763 @begin{Ramification}
3764 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3765 For example, if Storage_Unit = 8, and Word_Size = 32,
3766 then the user is allowed to specify a Component_Size of
3767 1, 2, 4, 8, 16, and 32, with no gaps.
3768 In addition, @i{n}*32 is allowed for positive integers @i{n},
3769 again with no gaps.
3770 If the implementation accepts Component_Size = 3,
3771 then it might allocate 10 components per word,
3772 with a 2-bit gap at the end of each word
3773 (unless @Chg{Version=[3],New=[Pack],Old=[packing]} is also specified),
3774 or it might not have any internal gaps at all.
3775 (There can be gaps at either end of the array.)
3776 @end{Ramification}
3777 @end{Itemize}
3778 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3779 Text=[The recommended level of support for the Component_Size attribute should
3780 be followed.]}]}
3781 @end{ImplAdvice}
3782
3783 @begin{StaticSem}
3784 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
3785 @ChgAdded{Version=[3],Type=[Leading],Text=[For
3786 @ChgPrefixType{Version=[3],Kind=[Added],Text=[a @nt{prefix} X that denotes
3787 an object]}:]}
3788 @begin(description)
3789 @ChgNote{ Original Version=[3],Kind=[Added]}
3790 @ChgAttribute{Version=[4],Kind=[RevisedAdded],ChginAnnex=[T],
3791 Leading=<F>, Prefix=<X>, AttrName=<Has_Same_Storage>, ARef=[AI05-0191-1],
3792 InitialVersion=[3], Text=[@Chg{Version=[3],New=[X'Has_Same_Storage denotes
3793 a function with the following specification:],Old=[]}
3794
3795 @begin(Descexample)
3796 @ChgRef{Version=[3],Kind=[Added]}
3797 @ChgAdded{Version=[3],Text=[@key(function) X'Has_Same_Storage (@RI{Arg} : @RI{any_type})
3798 @key(return) Boolean]}
3799 @end(Descexample)
3800
3801 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1],ARef=[AI05-0264-1]}
3802 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0077-1]}
3803 @ChgAdded{Version=[3],NoPrefix=[T],Text=[The actual parameter shall be a name
3804 that denotes an object. The object denoted by the actual parameter can be of
3805 any type. This function evaluates the names of the objects
3806 involved@Chg{Version=[4],New=[. It],Old=[ and]}
3807 returns True if the representation of the object denoted by the actual
3808 parameter occupies exactly the same bits as the representation of the object
3809 denoted by X@Chg{Version=[4],New=[ and the objects occupy at least
3810 one bit],Old=[]}; otherwise, it returns False.]}]}@Comment{End of Annex text here.}
3811
3812 @begin{Discussion}
3813 @ChgRef{Version=[3],Kind=[AddedNormal]}
3814 @ChgAdded{Version=[3],Text=[Has_Same_Storage means that, if the representation
3815 is contiguous, the objects sit at the same address and occupy the same length
3816 of memory.]}
3817 @end{Discussion}
3818 @end(description)
3819
3820 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
3821 @ChgAdded{Version=[3],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} X that
3822 denotes an object}:]}
3823 @begin(description)
3824 @ChgAttribute{Version=[3],Kind=[Added],ChginAnnex=[T],
3825 Leading=<F>, Prefix=<X>, AttrName=<Overlaps_Storage>, ARef=[AI05-0191-1],
3826 InitialVersion=[3], Text=[@Chg{Version=[3],New=[X'Overlaps_Storage denotes
3827 a function with the following specification:],Old=[]}
3828
3829 @begin(Descexample)
3830 @ChgRef{Version=[3],Kind=[Added]}
3831 @ChgAdded{Version=[3],Text=[@key(function) X'Overlaps_Storage (@RI{Arg} : @RI{any_type})
3832 @key(return) Boolean]}
3833 @end(Descexample)
3834
3835 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1],ARef=[AI05-0264-1]}
3836 @ChgAdded{Version=[3],NoPrefix=[T],Text=[The actual parameter shall be a name
3837 that denotes an object. The object denoted by the actual parameter can be of
3838 any type. This function evaluates the names of the objects involved and
3839 returns True if the representation of the object denoted by the actual
3840 parameter shares at least one bit with the representation of the object
3841 denoted by X; otherwise, it returns False.]}]}@Comment{End of Annex text here.}
3842 @end(description)
3843 @end{StaticSem}
3844
3845 @begin{Notes}
3846 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
3847 @ChgAdded{Version=[3],Text=[X'Has_Same_Storage(Y) implies X'Overlaps_Storage(Y).]}
3848
3849 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
3850 @ChgAdded{Version=[3],Text=[X'Has_Same_Storage(Y) and X'Overlaps_Storage(Y) are
3851 not considered to be reads of X and Y.]}
3852 @end{Notes}
3853
3854 @begin{StaticSem}
3855
3856 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
3857 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
3858 @ChgAdded{Version=[1],Text=[The following
3859 @Chg{Version=[3],New=[type-related ],Old=[]}operational attribute is
3860 defined: External_Tag.]}
3861
3862 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
3863 @Leading@;For @PrefixType{every subtype S of a tagged type @i(T)
3864 (specific or class-wide)}@Chg{New=[],Old=[, the following
3865 attribute is defined]}:
3866
3867 @begin{Description}
3868 @Comment{Original. @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
3869 Prefix=<S>, AttrName=<External_Tag>, Ref=[8652/0040], ARef=[AI95-00108-01], ...}
3870 We don't have a way to change multiple versions for attributes.}
3871 @ChgAttribute{Version=[3], Kind=[Revised], ChginAnnex=[F], Leading=[F],
3872 Prefix=<S>, AttrName=<External_Tag>, Ref=[8652/0040], ARef=[AI95-00108-01], ARef=[AI05-0092-1],
3873 InitialVersion=[0], Text=[@Defn{External_Tag clause}
3874 @PDefn2{Term=(specifiable), Sec=(of External_Tag for a tagged type)}
3875 S'External_Tag denotes an external string representation
3876 for S'Tag; it is of the predefined type String.
3877 External_Tag may be specified for a specific tagged type
3878 via an @nt{attribute_definition_clause};
3879 the expression of such a clause shall be static.@Chg{Version=[3],New=[@AspectDefn{External_Tag}],Old=[]}
3880 The default external tag representation is implementation defined.
3881 See @Chg{Version=[3],New=[],Old=[@RefSecNum{Dispatching Operations of Tagged Types}
3882 and ]}@RefSecNum{Stream-Oriented Attributes}.]}
3883 @Chg{New=[The value of External_Tag is never inherited@Redundant[; the
3884 default value is always used unless a new value is directly specified
3885 for a type].],Old=[]}
3886 @ImplDef{The default external representation for a type tag.}
3887 @end{Description}
3888 @EndPrefixType()
3889
3890 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[External_Tag],
3891 Text=[@ChgAdded{Version=[3],Text=[Unique identifier for a tagged type in
3892 streams.]}]}
3893
3894 @end{StaticSem}
3895
3896 @begin{RunTime}
3897 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0113-1]}
3898 @ChgAdded{Version=[3],Text=[If a user-specified external tag S'External_Tag is
3899 the same as T'External_Tag for some other tagged type declared by a different
3900 declaration in the partition, Program_Error is raised by the elaboration of the
3901 @nt{attribute_definition_clause}.]}
3902
3903 @begin{Ramification}
3904 @ChgRef{Version=[3],Kind=[AddedNormal]}
3905 @ChgAdded{Version=[3],Text=[This rule does not depend on the visibility of the
3906 other tagged type, but it does depend on the existence of the other tagged
3907 type. The other tagged type could have the default external tag or a
3908 user-specified external tag.]}
3909
3910 @ChgRef{Version=[3],Kind=[AddedNormal]}
3911 @ChgAdded{Version=[3],Text=[This rule allows the same declaration to be
3912 elaborated multiple times. In that case, different types could have the same
3913 external tag. If that happens, Internal_Tag would return some unspecified tag,
3914 and Descendant_Tag probably would return the intended tag (using the given
3915 ancestor to determine which type is intended). However, in some cases (such as
3916 multiple instantiations of a derived tagged type declared in a generic body),
3917 Tag_Error might be raised by Descendant_Tag if multiple types are identified.]}
3918
3919 @ChgRef{Version=[3],Kind=[AddedNormal]}
3920 @ChgAdded{Version=[3],Text=[Note that while there is a race condition inherent
3921 in this definition (which attribute_definition_clause raises Program_Error
3922 depends on the order of elaboration), it doesn't matter as a program with two
3923 such clauses is simply wrong. Two types that both come from the same
3924 declaration are allowed, as noted previously.]}
3925 @end{Ramification}
3926 @end{RunTime}
3927
3928 @begin{ImplReq}
3929 In an implementation, the default external tag for each specific tagged type
3930 declared in a partition
3931 shall be distinct, so long as the type is declared outside an
3932 instance of a generic body.
3933 If the compilation unit in which
3934 a given tagged type is declared, and all compilation units on which it
3935 semantically depends, are the same in two different partitions,
3936 then the external tag for the type shall be the same in the
3937 two partitions.
3938 What it means for a compilation unit to be the same in
3939 two different partitions is implementation defined.
3940 At a minimum, if the compilation unit is not recompiled
3941 between building the two different partitions that include it, the compilation
3942 unit is considered the same in the two partitions.
3943 @ImplDef{What determines whether a compilation unit is the
3944 same in two different partitions.}
3945 @begin{Reason}
3946 These requirements are important because external tags are used
3947 for input/output of class-wide types. These requirements ensure
3948 that what is written by one program can be read back by some other
3949 program so long as they share the same declaration for the
3950 type (and everything it depends on).
3951
3952 The user may specify the external tag if (s)he wishes its value
3953 to be stable even across changes to the compilation unit
3954 in which the type is declared (or changes in some unit on which it
3955 depends).
3956
3957 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3958 We use a String rather than a @Chg{Version=[2],
3959 New=[Stream_Element_Array],Old=[Storage_Array]} to represent an
3960 external tag for portability.
3961 @end{Reason}
3962 @begin{Ramification}
3963 Note that the characters
3964 of an external tag need not all be graphic characters.
3965 In other words, the external tag can be a sequence of arbitrary
3966 8-bit bytes.
3967 @end{Ramification}
3968 @end{ImplReq}
3969
3970 @begin{ImplPerm}
3971 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0113-1]}
3972 @ChgAdded{Version=[3],Text=[If a user-specified external tag S'External_Tag is
3973 the same as T'External_Tag for some other tagged type declared by a different
3974 declaration in the partition, the partition may be rejected.]}
3975
3976 @begin{Ramification}
3977 @ChgRef{Version=[3],Kind=[AddedNormal]}
3978 @ChgAdded{Version=[3],Text=[This is, in general, a post-compilation check.
3979 This permission is intended for implementations that do link-time construction
3980 of the external tag lookup table; implementations that dynamically construct
3981 the table will likely prefer to raise Program_Error upon elaboration of the
3982 problem construct. We don't want this check to require any implementation
3983 complexity, as it will be very rare that there would be a problem.]}
3984 @end{Ramification}
3985 @end{ImplPerm}
3986
3987 @begin{Notes}
3988 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00270-01]}
3989 The following language-defined attributes are specifiable,
3990 at least for some of the kinds of entities to which they apply:
3991 Address,
3992 @Chg{Version=[2],New=[],Old=[Size, Component_Size, ]}Alignment,
3993 @Chg{Version=[2],New=[Bit_Order, Component_Size, ],Old=[]}
3994 External_Tag,
3995 @Chg{Version=[2],New=[Input, Machine_Radix, Output, Read, Size, ],Old=[]}
3996 Small, @Chg{Version=[2],New=[],Old=[Bit_Order, ]}
3997 Storage_Pool, Storage_Size,
3998 @Chg{Version=[2],New=[Stream_Size, and ],Old=[]}
3999 Write@Chg{Version=[2],New=[],Old=[, Output, Read,
4000 Input, and Machine_Radix]}.
4001
4002 It follows from the general rules in @RefSecNum{Operational and Representation Aspects}
4003 that if one writes @lquotes@;@key[for] X'Size @key[use] Y;@rquotes@; then
4004 the X'Size @nt{attribute_reference} will return Y
4005 (assuming the implementation allows the Size clause).
4006 The same is true for all of the specifiable attributes except Storage_Size.
4007 @begin{Ramification}
4008 An implementation may specify that an implementation-defined attribute is
4009 specifiable for certain entities.
4010 This follows from the fact that the semantics of
4011 implementation-defined attributes is implementation defined.
4012 An implementation is not allowed to make a language-defined attribute
4013 specifiable if it isn't.
4014 @end{Ramification}
4015 @end{Notes}
4016
4017 @begin{Examples}
4018 @leading@keepnext@i{Examples of attribute definition clauses:}
4019 @begin{Example}
4020 Byte : @key[constant] := 8;
4021 Page : @key[constant] := 2**12;
4022
4023 @key[type] Medium @key[is] @key[range] 0 .. 65_000;
4024 @key[for] Medium'Size @key[use] 2*Byte;
4025 @key[for] Medium'Alignment @key[use] 2;
4026 Device_Register : Medium;
4027 @key[for] Device_Register'Size @key[use] Medium'Size;
4028 @key[for] Device_Register'Address @key[use] System.Storage_Elements.To_Address(16#FFFF_0020#);
4029
4030 @key[type] Short @key[is] @key[delta] 0.01 @key[range] -100.0 .. 100.0;
4031 @key[for] Short'Size @key[use] 15;
4032
4033 @key[for] Car_Name'Storage_Size @key[use] --@RI{ specify access type's storage pool size}
4034 2000*((Car'Size/System.Storage_Unit) +1); --@RI{ approximately 2000 cars}
4035
4036 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
4037 @key[function] @Chg{Version=[2],New=[My_Input],Old=[My_Read]}(Stream : @key[@Chg{Version=[2],New=[not null ],Old=[]}access] Ada.Streams.Root_Stream_Type'Class)
4038 @key[return] T;
4039 @key(for) T'@Chg{Version=[2],New=[Input],Old=[Read]} @key(use) @Chg{Version=[2],New=[My_Input],Old=[My_Read]}; --@RI{ see @RefSecNum{Stream-Oriented Attributes}}
4040 @end{Example}
4041 @end{Examples}
4042
4043 @begin{Notes}
4044 @i{Notes on the examples:}
4045 In the Size clause for Short,
4046 fifteen bits is the minimum necessary,
4047 since the type definition requires Short'Small <= 2**(@en@;7).
4048 @end{Notes}
4049
4050 @begin{Extend83}
4051 @Defn{extensions to Ada 83}
4052 The syntax rule for @ntf{length_clause} is replaced with the new syntax rule
4053 for @nt{attribute_definition_clause}, and it is modified to allow a
4054 @nt{name} (as well as an expression).
4055 @end{Extend83}
4056
4057 @begin{DiffWord83}
4058 The syntax rule for @nt{attribute_definition_clause} now requires that the
4059 prefix of the attribute be a @nt{local_name};
4060 in Ada 83 this rule was stated in the text.
4061
4062 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4063 In Ada 83, the relationship between a @Chg{Version=[2],New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]}
4064 specifying a certain aspect and an attribute that queried that
4065 aspect was unclear.
4066 In Ada 95, they are the same,
4067 except for certain explicit exceptions.
4068 @end{DiffWord83}
4069
4070 @begin{DiffWord95}
4071 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
4072 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify for
4073 each attribute whether it is an operational or representation attribute.]}
4074
4075 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]}
4076 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that
4077 External_Tag is never inherited.]}
4078
4079 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-01],ARef=[AI95-00291-01]}
4080 @ChgAdded{Version=[2],Text=[Adjusted the Recommended Level of Support for
4081 Alignment to eliminate nonsense requirements and to ensure that useful
4082 capabilities are required.]}
4083
4084 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-01],ARef=[AI95-00291-01]}
4085 @ChgAdded{Version=[2],Text=[Adjusted the Recommended Level of Support for
4086 Size to eliminate nonsense requirements and to ensure that useful
4087 capabilities are required. Also eliminated any dependence on whether an
4088 aspect was specified (a confirming representation item should not affect the
4089 semantics).]}
4090
4091 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
4092 @ChgAdded{Version=[2],Text=[Added the definition of machine scalar.]}
4093
4094 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00247-01]}
4095 @ChgAdded{Version=[2],Text=[Removed the requirement that specified
4096 alignments for a composite type cannot override those for their components,
4097 because it was never intended to apply to components whose location was
4098 specified with a representation item. Moreover, it causes a difference in
4099 legality when a confirming alignment is specified for one of the composite
4100 types.]}
4101
4102 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
4103 @ChgAdded{Version=[2],Text=[Removed recommended level of support rules about
4104 types with by-reference and aliased parts, because there are now blanket
4105 rules covering all recommended level of support rules.]}
4106
4107 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
4108 @ChgAdded{Version=[2],Text=[Split the definition of Alignment for subtypes
4109 and for objects. This simplified the wording and eliminated confusion about
4110 which rules applied to objects, which applied to subtypes, and which applied
4111 to both.]}
4112 @end{DiffWord95}
4113
4114 @begin{Inconsistent2005}
4115 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0095-1]}
4116 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
4117 @b<Correction:> An address attribute with a prefix of a generic formal
4118 subprogram whose actual parameter has convention Intrinsic now raises
4119 Program_Error. Since it is unlikely that such an attribute would have done
4120 anything useful (a subprogram with convention Intrinsic is not expected to
4121 have a normal subprogram body), it is highly unlikely that any existing
4122 programs would notice the difference, and any that do probably are buggy.]}
4123
4124 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0113-1]}
4125 @ChgAdded{Version=[3],Text=[@b<Correction:> User-specified
4126 external tags that conflict with other external tags raise Program_Error
4127 (or are optionally illegal). This was legal and did not raise an exception
4128 in the past, although the effects were not defined. So while a program
4129 might depend on such behavior, the results were not portable (even to
4130 different versions of the same implementation). Such programs should be
4131 rare.]}
4132 @end{Inconsistent2005}
4133
4134 @begin{Incompatible2005}
4135 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0095-1]}
4136 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b[Correction:]
4137 An address attribute with a prefix of a subprogram with convention Intrinsic is
4138 now illegal. Such attributes are very unlikely to have provided a useful
4139 answer (the intended meaning
4140 of convention Intrinsic is that there is no actual subprogram body for
4141 the operation), so this is highly unlikely to affect any existing programs
4142 unless they have a hidden bug.]}
4143 @end{Incompatible2005}
4144
4145 @begin{Extend2005}
4146 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0191-1]}
4147 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4148 Attributes Has_Same_Storage and Overlaps_Storage are new.]}
4149
4150 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
4151 @ChgAdded{Version=[3],Text=[Aspect Storage_Size is new;
4152 @nt{pragma} Storage_Size is now obsolescent, joining attribute
4153 Storage_Size for task types.]}
4154 @end{Extend2005}
4155
4156 @begin{DiffWord2005}
4157 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1]}
4158 @ChgAdded{Version=[3],Text=[@b<Correction:> Improved the description
4159 of erroneous execution for address clauses to make it clear that
4160 specifying an address inappropriate for the entity will lead to
4161 erroneous execution.]}
4162
4163 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0116-1]}
4164 @ChgAdded{Version=[3],Text=[@b<Correction:> Added @ImplAdviceTitle for
4165 the alignment of class-wide types.]}
4166 @end{DiffWord2005}
4167
4168 @begin{DiffWord2012}
4169 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0070-1]}
4170 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the behavior of
4171 Has_Same_Storage when 'Size = 0.]}
4172 @end{DiffWord2012}
4173
4174
4175
4176 @LabeledClause{Enumeration Representation Clauses}
4177
4178 @begin{Intro}
4179 @redundant[An @nt{enumeration_representation_clause} specifies the internal
4180 codes for enumeration literals.]
4181 @end{Intro}
4182
4183 @begin{Syntax}
4184 @Syn{lhs=<enumeration_representation_clause>,rhs="
4185 @key{for} @SynI{first_subtype_}@Syn2{local_name} @key{use} @Syn2{enumeration_aggregate};"}
4186 @Syn{lhs=<enumeration_aggregate>,rhs="@Syn2{array_aggregate}"}
4187 @end{Syntax}
4188
4189 @begin{Resolution}
4190 @PDefn2{Term=[expected type],
4191 Sec=(enumeration_representation_clause expressions)}
4192 The @nt<enumeration_aggregate> shall be written as a one-dimensional
4193 @nt<array_aggregate>, for which the index subtype is the unconstrained
4194 subtype of the enumeration type, and each component expression
4195 is expected to be of any integer type.
4196 @begin{Ramification}
4197 The @lquotes@;full coverage rules@rquotes@; for @nt<aggregate>s applies.
4198 An @key{others} is not allowed @em there is no applicable index
4199 constraint in this context.
4200 @end{Ramification}
4201 @end{Resolution}
4202
4203 @begin{Legality}
4204 The @SynI{first_subtype_}@nt{local_name} of an
4205 @nt{enumeration_representation_clause} shall denote an
4206 enumeration subtype.
4207 @begin{Ramification}
4208 As for all type-related representation items,
4209 the @nt{local_name} is required to denote a first subtype.
4210 @end{Ramification}
4211
4212 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
4213 @Chg{Version=[2],New=[Each component of the @nt{array_aggregate} shall be
4214 given by an @nt{expression} rather than a <>. ],Old=[]}The
4215 @Chg{Version=[2],New=[@nt{expression}s],Old=[expressions]} given in the
4216 @nt{array_aggregate} shall be static,
4217 and shall specify distinct integer codes for each value
4218 of the enumeration type; the associated integer codes shall
4219 satisfy the predefined ordering relation of the type.
4220 @begin{Reason}
4221 Each value of the enumeration type has to be given an internal code,
4222 even if the first subtype of the enumeration type is constrained
4223 to only a subrange (this is only possible if the enumeration type
4224 is a derived type). This @lquotes@;full coverage@rquotes@; requirement
4225 is important because one may refer to Enum'Base'First and Enum'Base'Last,
4226 which need to have defined representations.
4227 @end{Reason}
4228 @end{Legality}
4229
4230 @begin{StaticSem}
4231 @Chg{Version=[3],New=[@PDefn2{Term=[representation aspect], Sec=(coding)}],
4232 Old=[@PDefn2{Term=[aspect of representation], Sec=(coding)}
4233 @Defn2{Term=[coding], Sec=(aspect of representation)}]}
4234 An @nt{enumeration_representation_clause} specifies the
4235 @i{coding} aspect of representation.
4236 @Defn{internal code}
4237 The coding consists of the @i{internal code} for each enumeration
4238 literal, that is, the integral value used internally to
4239 represent each literal.@Chg{Version=[3],New=[@AspectDefn{Coding}],Old=[]}
4240
4241 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Coding],
4242 Text=[@ChgAdded{Version=[3],Text=[Internal representation of enumeration
4243 literals. Specified by an @nt{enumeration_representation_clause}, not
4244 by an @nt{aspect_specification}.]}]}
4245
4246 @end{StaticSem}
4247
4248 @begin{ImplReq}
4249 For nonboolean enumeration types,
4250 if the coding is not specified for the type, then
4251 for each value of the type, the internal code shall be equal to
4252 its position number.
4253 @begin{Reason}
4254 This default representation is already used by all known
4255 Ada compilers for nonboolean enumeration types. Therefore,
4256 we make it a requirement so users can depend on it, rather
4257 than feeling obliged to supply for every enumeration type
4258 an enumeration representation clause that is equivalent
4259 to this default rule.
4260 @end{Reason}
4261 @begin{Discussion}
4262 For boolean types, it is relatively common to use all ones for
4263 True, and all zeros for False, since some hardware supports
4264 that directly. Of course, for a one-bit Boolean object
4265 (like in a packed array), False is presumably zero and True
4266 is presumably one (choosing the reverse would be extremely
4267 unfriendly!).
4268 @end{Discussion}
4269 @end{ImplReq}
4270
4271 @begin{ImplAdvice}
4272 @Leading@PDefn2{Term=[recommended level of support], Sec=(@nt{enumeration_representation_clause})}
4273 The recommended level of support for @nt{enumeration_representation_clause}s is:
4274 @begin{Itemize}
4275 An implementation should support at least the internal codes in the
4276 range System.Min_Int..System.Max_Int. An implementation need not support
4277 @nt{enumeration_@!representation_@!clause}s for boolean types.
4278 @begin{Ramification}
4279 The implementation may support numbers outside the above
4280 range, such as numbers greater than System.Max_Int.
4281 See AI83-00564.
4282 @end{Ramification}
4283 @begin{Reason}
4284 The benefits of specifying the internal coding of a boolean type do
4285 not outweigh the implementation costs.
4286 Consider, for example, the implementation of the logical operators on
4287 a packed array of booleans with strange internal codes.
4288 It's implementable, but not worth it.
4289 @end{Reason}
4290 @end{Itemize}
4291 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4292 Text=[The recommended level of support for
4293 @nt{enumeration_representation_clause}s should be followed.]}]}
4294 @end{ImplAdvice}
4295
4296 @begin{Notes}
4297 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4298 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
4299 Unchecked_Conversion may be used to query the internal codes used
4300 for an enumeration type.
4301 The attributes of the type, such as Succ, Pred, and Pos,
4302 are unaffected by the @Chg{New=[@nt{enumeration_representation_clause}],Old=[@nt{representation_clause}]}.
4303 For example, Pos always returns the position number, @i{not} the
4304 internal integer code that might have been specified in
4305 @Chg{New=[an @nt{enumeration_representation_clause}],
4306 Old=[a @nt{representation_clause}]}@Chg<Version=[3],New=[],Old=[}]>.
4307 @begin{Discussion}
4308 @Leading@;Suppose the enumeration type in question is derived:
4309 @begin{Example}
4310 @key[type] T1 @key[is] (Red, Green, Blue);
4311 @key[subtype] S1 @key[is] T1 @key[range] Red .. Green;
4312 @key[type] S2 @key[is] @key[new] S1;
4313 @key[for] S2 @key[use] (Red => 10, Green => 20, Blue => 30);
4314 @end{Example}
4315
4316 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4317 @Leading@;The @Chg{New=[@nt{enumeration_representation_clause}],Old=[@nt{representation_clause}]}
4318 has to specify values for all enumerals, even ones that are not in S2 (such as
4319 Blue). The Base attribute can be used to get at these values.
4320 For example:
4321 @begin{Example}
4322 @key[for] I @key[in] S2'Base @key[loop]
4323 ... --@RI{ When I equals Blue, the internal code is 30.}
4324 @key[end] @key[loop];
4325 @end{Example}
4326
4327 We considered allowing or requiring
4328 @lquotes@;@key[for] S2'Base @key[use] ...@rquotes@; in cases like this,
4329 but it didn't seem worth the trouble.
4330 @end{Discussion}
4331 @end{Notes}
4332
4333 @begin{Examples}
4334 @leading@keepnext@i{Example of an enumeration representation clause:}
4335 @begin{Example}
4336 @key[type] Mix_Code @key[is] (ADD, SUB, MUL, LDA, STA, STZ);
4337
4338 @key[for] Mix_Code @key[use]
4339 (ADD => 1, SUB => 2, MUL => 3, LDA => 8, STA => 24, STZ =>33);
4340 @end{Example}
4341 @end{Examples}
4342
4343 @begin{Extend83}
4344 @Defn{extensions to Ada 83}
4345 As in other similar contexts, Ada 95 allows expressions of any integer type,
4346 not just expressions of type @i{universal_integer}, for the component
4347 expressions in the @nt<enumeration_aggregate>. The preference rules
4348 for the predefined operators of @i{root_integer} eliminate
4349 any ambiguity.
4350
4351 For portability, we now require that the default coding for an enumeration
4352 type be the @lquotes@;obvious@rquotes@; coding using position numbers.
4353 This is satisfied by all known implementations.
4354 @end{Extend83}
4355
4356 @begin{DiffWord95}
4357 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
4358 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Updated to reflect that we
4359 no longer have something called @ntf{representation_clause}.]}
4360
4361 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
4362 @ChgAdded{Version=[2],Text=[Added wording to prevent the use of <> in a
4363 @nt{enumeration_representation_clause}. (<> is newly added to
4364 @nt{array_aggregate}s.)]}
4365 @end{DiffWord95}
4366
4367
4368
4369 @LabeledClause{Record Layout}
4370
4371 @begin{Intro}
4372 @Chg{Version=[3],New=[@AspectDefn{Layout}
4373 @PDefn2{Term=[representation aspect], Sec=(layout)}
4374 @PDefn2{Term=[representation aspect], Sec=(record layout)}
4375 @AspectDefn{Record layout}
4376 @PDefn2{Term=[representation aspect], Sec=(storage place)}
4377 @Defn2{Term=[storage place], Sec=(representation aspect)}
4378 @Defn2{Term=[storage place], Sec=(of a component)}],
4379 Old=[@PDefn2{Term=[aspect of representation], Sec=(layout)}
4380 @Defn2{Term=[layout], Sec=(aspect of representation)}
4381 @PDefn2{Term=[aspect of representation], Sec=(record layout)}
4382 @Defn2{Term=[record layout], Sec=(aspect of representation)}
4383 @PDefn2{Term=[aspect of representation], Sec=(storage place)}
4384 @Defn2{Term=[storage place], Sec=(of a component)}]}
4385 The @i{(record) layout} aspect of representation
4386 consists of the @i{storage places} for some or all components,
4387 that is, storage place attributes of the components.
4388 The layout can be specified with a @nt{record_@!representation_@!clause}.
4389 @end{Intro}
4390
4391
4392 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
4393 @LabeledSubClause{Record Representation Clauses}
4394
4395 @begin{Intro}
4396 @redundant[A @nt{record_representation_clause} specifies the storage representation
4397 of records and record extensions, that is, the order, position, and size
4398 of components (including discriminants, if any).
4399 @IndexSee{Term=[bit field],See=(record_representation_clause)}]
4400 @end{Intro}
4401
4402 @begin{MetaRules}
4403 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4404 It should be feasible for an implementation to use negative offsets
4405 in the representation of composite types.
4406 However, no implementation should be forced to support negative
4407 offsets.
4408 Therefore@Chg{Version=[2],New=[, in the interest of uniformity],Old=[]},
4409 negative offsets should be disallowed in
4410 @nt{record_representation_clause}s.
4411 @end{MetaRules}
4412
4413 @begin{Syntax}
4414 @Syn{lhs=<record_representation_clause>,rhs="
4415 @key{for} @SynI{first_subtype_}@Syn2{local_name} @key{use}
4416 @key{record} [@Syn2{mod_clause}]
4417 {@Syn2{component_clause}}
4418 @key{end} @key{record};"}
4419
4420
4421 @Syn{lhs=<component_clause>,rhs="
4422 @SynI{component_}@Syn2{local_name} @key{at} @Syn2{position} @key{range} @Syn2{first_bit} .. @Syn2{last_bit};"}
4423
4424 @Syn{lhs=<position>,rhs="@SynI{static_}@Syn2{expression}"}
4425 @Syn{lhs=<first_bit>,rhs="@SynI{static_}@Syn2{simple_expression}"}
4426 @Syn{lhs=<last_bit>,rhs="@SynI{static_}@Syn2{simple_expression}"}
4427 @begin{Reason}
4428 @nt{First_bit} and @nt{last_bit} need to be @nt{simple_expression}
4429 instead of @nt{expression} for the same reason as in @nt{range}
4430 (see @RefSec{Scalar Types}).
4431 @end{Reason}
4432 @end{Syntax}
4433
4434 @begin{Resolution}
4435 @PDefn2{Term=[expected type],
4436 Sec=(component_clause expressions)}
4437 @PDefn2{Term=[expected type],
4438 Sec=(position)}
4439 @PDefn2{Term=[expected type],
4440 Sec=(first_bit)}
4441 @PDefn2{Term=[expected type],
4442 Sec=(last_bit)}
4443 Each @nt{position}, @nt{first_bit}, and @nt{last_bit} is expected to
4444 be of any integer type.
4445 @begin{Ramification}
4446 These need not have the same integer type.
4447 @end{Ramification}
4448 @end{Resolution}
4449
4450 @begin{Legality}
4451 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00436-01]}
4452 The @SynI{first_subtype_}@nt{local_name} of a
4453 @nt{record_representation_clause} shall denote a specific
4454 @Chg{Version=[2],New=[],Old=[nonlimited ]}record or record extension subtype.
4455 @begin{Ramification}
4456 As for all type-related representation items,
4457 the @nt{local_name} is required to denote a first subtype.
4458 @end{Ramification}
4459
4460 If the @i{component_}@nt<local_name> is a @nt<direct_name>,
4461 the @nt{local_name} shall denote a component of the type.
4462 For a record extension, the component shall not be inherited,
4463 and shall not be a discriminant that corresponds to a discriminant of
4464 the parent type.
4465 If the @i{component_}@!@nt<local_@!name> has an @nt{attribute_@!designator},
4466 the @nt{direct_@!name} of the @nt<local_@!name> shall denote either
4467 the declaration of the type or a component of the type,
4468 and the @nt{attribute_@!designator} shall denote an
4469 implementation-defined implicit component of the type.
4470
4471 The @nt{position}, @nt{first_bit}, and @nt{last_bit} shall be
4472 static expressions.
4473 The value of @nt{position} and @nt{first_bit} shall be nonnegative.
4474 The value of @nt{last_bit} shall be no less than
4475 @nt{first_bit} @en 1.
4476 @begin{Ramification}
4477 A @nt{component_clause} such as
4478 @lquotes@;X @key{at} 4 @key{range} 0..@en@;1;@rquotes@;
4479 is allowed if X can fit in zero bits.
4480 @end{Ramification}
4481
4482 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
4483 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[If the
4484 nondefault bit ordering applies to the type, then either:]}
4485 @begin{Itemize}
4486 @ChgRef{Version=[2],Kind=[Added]}
4487 @ChgAdded{Version=[2],Text=[the value of @nt{last_bit} shall be
4488 less than the size of the largest machine scalar; or]}
4489
4490 @ChgRef{Version=[2],Kind=[Added]}
4491 @ChgAdded{Version=[2],Text=[the value of @nt{first_bit} shall be zero and the
4492 value of @nt{last_bit} + 1 shall be a multiple of System.Storage_Unit.]}
4493 @end{Itemize}
4494
4495 At most one @nt{component_clause} is allowed for each component of
4496 the type, including for each discriminant
4497 (@nt{component_clause}s may be given for some, all, or none of the
4498 components).
4499 Storage places within a @nt{component_list} shall not overlap,
4500 unless they are for components in distinct @nt{variant}s of the same
4501 @nt{variant_part}.
4502
4503 A name that denotes a component of a type is not allowed within
4504 a @nt{record_representation_clause} for the type,
4505 except as the @SynI{component_}@nt<local_name>
4506 of a @nt{component_clause}.
4507 @begin{Reason}
4508 @Leading@;It might seem strange to make the
4509 @nt{record_representation_clause} part of the declarative region,
4510 and then disallow mentions of the components within almost all of
4511 the @nt{record_representation_clause}.
4512 The alternative would be to treat the
4513 @SynI{component_}@nt<local_name> like a formal parameter name in
4514 a subprogram call (in terms of visibility).
4515 However, this rule would imply slightly different semantics,
4516 because (given the actual rule)
4517 the components can hide other declarations.
4518 This was the rule in Ada 83, and we see no reason to change it.
4519 The following, for example, was and is illegal:
4520 @begin{Example}
4521 @key[type] T @key[is]
4522 @key[record]
4523 X : Integer;
4524 @key[end] @key[record];
4525 X : @key[constant] := 31; --@RI{ Same defining name as the component.}
4526 @key[for] T @key[use]
4527 @key[record]
4528 X @key[at] 0 @key[range] 0..X; --@RI{ Illegal!}
4529 @key[end] @key[record];
4530 @end{Example}
4531
4532 The component X hides the named number X throughout
4533 the @nt{record_representation_clause}.
4534 @end{Reason}
4535 @end{Legality}
4536
4537 @begin{StaticSem}
4538 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
4539 A @nt{record_representation_clause}
4540 (without the @nt{mod_clause})
4541 specifies the layout.@Chg{Version=[2],New=[],Old=[
4542 The storage place
4543 attributes (see @RefSecNum{Storage Place Attributes})
4544 are taken from the
4545 values of the @nt{position}, @nt{first_bit},
4546 and @nt{last_bit} expressions
4547 after normalizing those values so that
4548 @nt{first_bit} is less than
4549 Storage_Unit.@Chg{Version=[3],New=[@AspectDefn{Layout (record)}],Old=[]}]}
4550
4551 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Layout (record)],
4552 Text=[@ChgAdded{Version=[3],Text=[Layout of record components. Specified by
4553 a @nt{record_representation_clause}, not by an @nt{aspect_specification}.]}]}
4554
4555 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Record layout],
4556 Text=[@ChgAdded{Version=[3],Text=[See Layout.]}]}
4557
4558 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
4559 @ChgAdded{Version=[2],Text=[If the default bit ordering applies to the type,
4560 the @nt{position}, @nt{first_bit}, and @nt{last_bit} of each
4561 @nt{component_clause} directly specify
4562 the position and size of the corresponding component.]}
4563
4564 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
4565 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
4566 @ChgAdded{Version=[2],Type=[Leading],Text=[If the nondefault bit ordering
4567 applies to the type@Chg{Version=[3],New=[,],Old=[]} then
4568 the layout is determined as follows:]}
4569 @begin{Itemize}
4570 @ChgRef{Version=[2],Kind=[Added]}
4571 @ChgAdded{Version=[2],Text=[the @nt{component_clause}s for which the value of
4572 @nt{last_bit} is greater than or equal to the size of the largest machine scalar
4573 directly specify the position and size of the corresponding component;]}
4574
4575 @ChgRef{Version=[2],Kind=[Added]}
4576 @ChgAdded{Version=[2],Text=[for other @nt{component_clause}s, all of the
4577 components having the same value of @nt{position} are considered to be part of
4578 a single machine scalar, located at that @nt{position}; this machine scalar
4579 has a size which is the smallest machine scalar size larger than the largest
4580 @nt{last_bit} for all @nt{component_clause}s at that @nt{position}; the
4581 @nt{first_bit} and @nt{last_bit} of each @nt{component_clause} are then
4582 interpreted as bit offsets in this machine scalar.]}
4583 @end{Itemize}
4584
4585 @begin{Ramification}
4586 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00133-01]}
4587 @ChgNote{We want the header title to remain, so we use @Chg instead if @ChgDeleted.}
4588 @Chg{Version=[2],New=[],Old=[For example,
4589 if Storage_Unit is 8, then
4590 @lquotes@;C @key[at] 0 @key[range] 24..31;@rquotes@;
4591 defines C'Position = 3, C'First_Bit = 0, and C'Last_Bit = 7.
4592 This is true of machines with either bit ordering.]}
4593
4594 A @nt{component_clause} also determines the value of the Size
4595 attribute of the component,
4596 since this attribute is related to First_Bit and Last_Bit.
4597 @end{Ramification}
4598
4599 @Redundant[A @nt{record_representation_clause} for a record extension
4600 does not override the layout of the parent part;]
4601 if the layout was specified for the parent type,
4602 it is inherited by the record extension.
4603 @end{StaticSem}
4604
4605 @begin{ImplPerm}
4606 An implementation may generate implementation-defined components (for
4607 example, one containing the offset of another component).
4608 An implementation may generate names that denote
4609 such implementation-defined components;
4610 such names shall be implementation-defined @nt{attribute_reference}s.
4611 An implemen@!tation may allow such implementation-defined names to be
4612 used in @nt{record_@!representation_@!clause}s.
4613 An implementation can restrict such @nt{component_@!clause}s in any
4614 manner it sees fit.
4615 @ImplDef{Implementation-defined components.}
4616 @begin{Ramification}
4617 Of course, since the semantics of implementation-defined
4618 attributes is implementation defined, the implementation need not
4619 support these names in all situations.
4620 They might be purely for the purpose of @nt{component_clause}s,
4621 for example.
4622 The visibility rules for such names are up to the implementation.
4623
4624 We do not allow such component names to be normal identifiers
4625 @em that would constitute blanket permission to do all kinds of evil
4626 things.
4627 @end{Ramification}
4628 @begin{Discussion}
4629 @Defn{dope}
4630 Such implementation-defined components are known in the
4631 vernacular as @lquotes@;dope.@rquotes@;
4632 Their main purpose is for storing offsets of components that depend
4633 on discriminants.
4634 @end{Discussion}
4635
4636 If a @nt<record_representation_clause> is given for an untagged derived type,
4637 the storage place attributes for all of the components of the derived
4638 type may differ
4639 from those of the corresponding components of the parent type,
4640 even for components whose storage
4641 place is not specified explicitly in the @nt<record_@!representation_@!clause>.
4642 @begin{Reason}
4643 This is clearly necessary, since the whole record may need to be
4644 laid out differently.
4645 @end{Reason}
4646 @end{ImplPerm}
4647
4648 @begin{ImplAdvice}
4649 @Leading@PDefn2{Term=[recommended level of support], Sec=(@nt{record_representation_clause})}
4650 The recommended level of support for @nt{record_representation_clause}s is:
4651 @begin{Itemize}
4652 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
4653 @ChgAdded{Version=[2],Text=[An implementation should support machine scalars
4654 that correspond to all of the integer, floating point, and address formats
4655 supported by the machine.]}
4656
4657 An implementation should support storage places that can be extracted
4658 with a load, mask, shift sequence of machine code,
4659 and set with a load, shift, mask, store sequence,
4660 given the available machine instructions and run-time model.
4661
4662 A storage place should be supported if its size is equal to the Size
4663 of the component subtype,
4664 and it starts and ends on a boundary that obeys the Alignment of the
4665 component subtype.
4666
4667 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
4668 @Chg{Version=[2],New=[For],Old=[If the default bit ordering applies to
4669 the declaration of a given type, then for]} a component
4670 @Chg{Version=[2],New=[with a subtype ],Old=[]}whose
4671 @Chg{Version=[2],New=[],Old=[subtype's ]}Size is less than the word size, any
4672 storage place that does not cross an aligned word boundary should be supported.
4673
4674 @begin{Reason}
4675 The above recommendations are sufficient to
4676 define interfaces to most interesting hardware.
4677 This causes less implementation burden than the definition in ACID,
4678 which requires arbitrary bit alignments of arbitrarily large
4679 components.
4680 Since the ACID definition is neither enforced by the ACVC,
4681 nor supported by all implementations,
4682 it seems OK for us to weaken it.
4683 @end{Reason}
4684
4685 An implementation may reserve a storage place for the tag
4686 field of a tagged type, and disallow other components from overlapping
4687 that place.
4688 @begin{Ramification}
4689 Similar permission for other dope is not granted.
4690 @end{Ramification}
4691
4692 An implementation need not support a
4693 @nt{component_clause} for a component of an extension part
4694 if the storage place is not after the storage places of all components
4695 of the parent type, whether or not those storage places had been specified.
4696 @begin{Reason}
4697 These restrictions are probably necessary if block equality
4698 operations are to be feasible for class-wide types.
4699 For block comparison to work, the implementation typically has to fill
4700 in any gaps with zero (or one) bits.
4701 If a @lquotes@;gap@rquotes@; in the parent type is filled in with a component in a
4702 type extension, then this won't work when a class-wide object is
4703 passed by reference, as is required.
4704 @end{Reason}
4705 @end{Itemize}
4706 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4707 Text=[The recommended level of support for @nt{record_representation_clause}s
4708 should be followed.]}]}
4709 @end{ImplAdvice}
4710
4711 @begin{Notes}
4712 If no @nt{component_clause} is given for a component, then the
4713 choice of the storage place for the component is left to the
4714 implementation. If @nt{component_clause}s are given for all components,
4715 the @nt{record_representation_clause} completely specifies the
4716 representation of the type and will be obeyed exactly by the
4717 implementation.
4718 @begin{Ramification}
4719 The
4720 visibility rules prevent the name of a component of the type from
4721 appearing in a @nt{record_representation_clause} at any place
4722 @i{except} for the @SynI{component_}@nt<local_name> of a
4723 @nt{component_clause}.
4724 However, since the @nt{record_representation_clause} is part of the
4725 declarative region of the type declaration,
4726 the component names hide outer homographs throughout.
4727
4728 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4729 A @nt{record_representation_clause} cannot be given for a protected type,
4730 even though protected types, like record types, have components.
4731 The primary reason for this rule is that there is likely to be too
4732 much dope in a protected type @em entry queues,
4733 bit maps for barrier values, etc.
4734 In order to control the representation of the user-defined components, simply
4735 declare a record type, give it a
4736 @Chg{New=[@nt{record_@!representation_@!clause}],Old=[@nt{representation_clause}]},
4737 and give the protected type one component whose type is the record type.
4738 Alternatively, if the protected object is protecting something like a
4739 device register, it makes more sense to keep the thing being
4740 protected outside the protected object (possibly with a pointer to it
4741 in the protected object), in order to keep implementation-defined
4742 components out of the way.
4743 @end{Ramification}
4744 @end{Notes}
4745
4746 @begin{Examples}
4747 @leading@keepnext@i{Example of specifying the layout of a record type:}
4748 @begin{Example}
4749 Word : @key[constant] := 4; --@RI{ storage element is byte, 4 bytes per word}
4750
4751 @key[type] State @key[is] (A,M,W,P);
4752 @key[type] Mode @key[is] (Fix, Dec, Exp, Signif);
4753
4754 @key[type] Byte_Mask @key[is] @key[array] (0..7) @key[of] Boolean;
4755 @key[type] State_Mask @key[is] @key[array] (State) @key[of] Boolean;
4756 @key[type] Mode_Mask @key[is] @key[array] (Mode) @key[of] Boolean;
4757
4758 @key[type] Program_Status_Word @key[is]
4759 @key[record]
4760 System_Mask : Byte_Mask;
4761 Protection_Key : Integer @key[range] 0 .. 3;
4762 Machine_State : State_Mask;
4763 Interrupt_Cause : Interruption_Code;
4764 Ilc : Integer @key[range] 0 .. 3;
4765 Cc : Integer @key[range] 0 .. 3;
4766 Program_Mask : Mode_Mask;
4767 Inst_Address : Address;
4768 @key[end] @key[record];
4769
4770 @key[for] Program_Status_Word @key[use]
4771 @key[record]
4772 System_Mask @key[at] 0*Word @key[range] 0 .. 7;
4773 Protection_Key @key[at] 0*Word @key[range] 10 .. 11; --@RI{ bits 8,9 unused}
4774 Machine_State @key[at] 0*Word @key[range] 12 .. 15;
4775 Interrupt_Cause @key[at] 0*Word @key[range] 16 .. 31;
4776 Ilc @key[at] 1*Word @key[range] 0 .. 1; --@RI{ second word}
4777 Cc @key[at] 1*Word @key[range] 2 .. 3;
4778 Program_Mask @key[at] 1*Word @key[range] 4 .. 7;
4779 Inst_Address @key[at] 1*Word @key[range] 8 .. 31;
4780 @key[end] @key[record];
4781
4782 @key[for] Program_Status_Word'Size @key[use] 8*System.Storage_Unit;
4783 @key[for] Program_Status_Word'Alignment @key[use] 8;
4784 @end{Example}
4785 @end{Examples}
4786
4787 @begin{Notes}
4788 @i{Note on the example:}
4789 The @nt{record_representation_clause} defines the record layout. The
4790 Size clause guarantees that (at least) eight storage elements are used
4791 for objects of the type. The Alignment clause guarantees that
4792 aliased, imported, or exported objects of the type will have
4793 addresses divisible by eight.
4794 @end{Notes}
4795
4796
4797 @begin{DiffWord83}
4798 The @ntf{alignment_clause} has been renamed to @nt{mod_clause} and moved
4799 to @RefSec{Obsolescent Features}.
4800
4801 We have clarified that implementation-defined component names have to be
4802 in the form of an @nt{attribute_reference} of a component or of the
4803 first subtype itself;
4804 surely Ada 83 did not intend to allow arbitrary identifiers.
4805
4806 The RM83-13.4(7) wording incorrectly allows components in
4807 nonvariant records to overlap.
4808 We have corrected that oversight.
4809 @end{DiffWord83}
4810
4811 @begin{Incompatible95}
4812 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
4813 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
4814 @b[Amendment Correction:] The meaning of a @nt{record_representation_clause}
4815 for the nondefault
4816 bit order is now clearly defined. Thus, such clauses can be portably
4817 written. In order to do that though, the equivalence of bit 1 in word 1 to
4818 bit 9 in word 0 (for a machine with Storage_Unit = 8) had to be dropped for
4819 the nondefault bit order. Any @nt{record_representation_clause}s which
4820 depends on that equivalence will break (although such code would imply a
4821 noncontiguous representation for a component, and it seems unlikely that
4822 compilers were supporting that anyway).]}
4823 @end{Incompatible95}
4824
4825 @begin{Extend95}
4826 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00436-01]}
4827 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4828 @b[Amendment Correction:] The undocumented (and
4829 likely unintentional) incompatibility with Ada 83 caused by not allowing
4830 @nt{record_representation_clause}s on limited record types is removed.]}
4831 @end{Extend95}
4832
4833 @LabeledSubClause{Storage Place Attributes}
4834
4835 @begin{StaticSem}
4836 @Leading@Defn2{Term=[storage place attributes], Sec=(of a component)}
4837 For @PrefixType{a component C of a composite, non-array
4838 object R},
4839 the @i{storage place attributes} are defined:
4840 @begin{Ramification}
4841 The storage place attributes are not (individually) specifiable,
4842 but the user may control their values by giving a
4843 @nt{record_representation_clause}.
4844 @end{Ramification}
4845 @begin{Description}
4846 @ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T],
4847 Leading=<F>, Prefix=<R.C>, AttrName=<Position>,
4848 ARef=[AI95-00133-01], InitialVersion=[0],
4849 Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the
4850 composite type, and if a @nt{component_clause} specifies the placement of C,
4851 denotes the value given for the @nt{position} of the @nt{component_clause};
4852 otherwise, denotes],Old=[Denotes]} the same value as R.C'Address @en@;
4853 R'Address. The value of this attribute is of the type
4854 @i{universal_integer}.>}
4855 @begin{Ramification}
4856 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
4857 Thus, @Chg{Version=[2],New=[for the default bit order, ],Old=[]}R.C'Position
4858 is the offset of C in storage
4859 elements from the beginning of the object,
4860 where the first storage element of an object is numbered zero.
4861 R'Address + R.C'Position = R.C'Address.
4862 For record extensions, the offset is not measured from
4863 the beginning of the extension part, but from the
4864 beginning of the whole object, as usual.
4865
4866 In @lquotes@;R.C'Address @en@; R'Address@rquotes@;,
4867 the "@en@;" operator is the one in System.Storage_Elements
4868 that takes two Addresses and returns a Storage_Offset.
4869 @end{Ramification}
4870
4871 @ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T],
4872 Leading=<F>, Prefix=<R.C>, AttrName=<First_Bit>,
4873 ARef=[AI95-00133-01], InitialVersion=[0],
4874 Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the
4875 composite type, and if a @nt{component_clause} specifies the placement of C,
4876 denotes the value given for the @nt{first_bit} of the @nt{component_clause};
4877 otherwise, denotes],Old=[Denotes]} the offset, from the start of the first
4878 of the storage elements occupied by C, of the first bit occupied by C.
4879 This offset is measured in bits.
4880 The first bit of a storage element is numbered zero.
4881 The value of this attribute is of the type
4882 @i{universal_integer}.>}
4883
4884 @ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T],
4885 Leading=<F>, Prefix=<R.C>, AttrName=<Last_Bit>,
4886 ARef=[AI95-00133-01], InitialVersion=[0],
4887 Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the
4888 composite type, and if a @nt{component_clause} specifies the placement of C,
4889 denotes the value given for the @nt{last_bit} of the @nt{component_clause};
4890 otherwise, denotes],Old=[Denotes]} the offset, from the start of the first
4891 of the storage elements occupied by C, of the last bit occupied by C.
4892 This offset is measured in bits. The value of this attribute
4893 is of the type @i{universal_integer}.>}
4894 @begin{Ramification}
4895 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4896 The ordering of bits in a storage element is
4897 @Chg{Version=[2],New=[],Old=[is ]}defined in @RefSec{Bit Ordering}.
4898
4899 R.C'Size = R.C'Last_Bit @en@; R.C'First_Bit + 1.
4900 (Unless the implementation chooses an indirection
4901 representation.)
4902
4903 If a @nt{component_clause} applies to a component,
4904 then that component will be at the same relative storage place
4905 in all objects of the type.
4906 Otherwise, there is no such requirement.
4907 @end{Ramification}
4908 @end{Description}
4909 @EndPrefixType{}
4910 @end{StaticSem}
4911
4912 @begin{ImplAdvice}
4913 @PDefn{contiguous representation}
4914 @PDefn{discontiguous representation}
4915 If a component is represented using some form of pointer (such as an
4916 offset) to the actual data of the component, and this data is contiguous with
4917 the rest of the object, then the storage place attributes should reflect
4918 the place of the actual data, not the pointer.
4919 If a component is allocated discontiguously from the rest of the object,
4920 then a warning should be generated upon reference to one
4921 of its storage place attributes.
4922 @begin{Reason}
4923 For discontiguous components, these attributes make no sense.
4924 For example, an implementation might allocate dynamic-sized components
4925 on the heap.
4926 For another example, an implementation might allocate the discriminants
4927 separately from the other components, so that multiple objects of the
4928 same subtype can share discriminants.
4929 Such representations cannot happen if there is a @nt{component_clause}
4930 for that component.
4931 @end{Reason}
4932 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4933 Text=[If a component is represented using a pointer to the actual data of
4934 the component which is contiguous with
4935 the rest of the object, then the storage place attributes should reflect
4936 the place of the actual data.
4937 If a component is allocated discontiguously from the rest of the object,
4938 then a warning should be generated upon reference to one
4939 of its storage place attributes.]}]}
4940 @end{ImplAdvice}
4941
4942 @begin{Incompatible95}
4943 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
4944 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
4945 @b[Amendment Correction:] The meaning of the storage place attributes for
4946 the nondefault
4947 bit order is now clearly defined, and can be different than that given by
4948 strictly following the Ada 95 wording. Any code which depends on the
4949 original Ada 95 values for a type using the nondefault bit order where
4950 they are different will break.]}
4951 @end{Incompatible95}
4952
4953
4954
4955 @LabeledSubClause{Bit Ordering}
4956
4957 @begin{Intro}
4958 @redundant[The Bit_Order attribute specifies the interpretation of the storage
4959 place attributes.]
4960 @begin{Reason}
4961 The intention is to provide uniformity in the
4962 interpretation of storage places across implementations on a
4963 particular machine by allowing the user to specify the Bit_Order.
4964 It is not intended to fully support data interoperability across
4965 different machines,
4966 although it can be used for that purpose in some situations.
4967
4968 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4969 We can't require all implementations on a given machine to use the same
4970 bit ordering by default;
4971 if the user cares, a @Chg{Version=[2],New=[],Old=[@nt{pragma} ]}Bit_Order
4972 @Chg{Version=[2],New=[@nt{attribute_definition_clause} ],Old=[]}can be used
4973 to force all implementations to use the same bit ordering.
4974 @end{Reason}
4975 @end{Intro}
4976
4977 @begin{StaticSem}
4978 @Defn{bit ordering}
4979 A bit ordering is a method of interpreting the meaning of the
4980 storage place attributes.
4981 @Defn{High_Order_First}
4982 @Defn{big endian}
4983 @Defn2{Term=[endian], Sec=(big)}
4984 High_Order_First @Redundant[(known in the vernacular as @lquotes@;big endian@rquotes@;)]
4985 means that the first bit of a storage element
4986 (bit 0) is the most significant bit (interpreting the sequence of
4987 bits that represent a component as an unsigned integer value).
4988 @Defn{Low_Order_First}
4989 @Defn{little endian}
4990 @Defn2{Term=[endian], Sec=(little)}
4991 Low_Order_First @Redundant[(known in the vernacular as @lquotes@;little endian@rquotes@;)]
4992 means the opposite: the first bit is the least significant.
4993
4994 @Leading@;For @PrefixType{every specific record subtype S},
4995 the following attribute is defined:
4996 @begin{Description}
4997 @Attribute{Prefix=<S>, AttrName=<Bit_Order>,
4998 Text=<Denotes the bit ordering for the type of S.
4999 The value of this attribute is of type System.Bit_Order.>}
5000 @EndPrefixType{}
5001 @PDefn2{Term=[specifiable], Sec=(of Bit_Order for record types and
5002 record extensions)}
5003 @Defn{Bit_Order clause}
5004 Bit_Order may be specified for specific record types
5005 via an @nt{attribute_definition_clause};
5006 the expression of such a clause shall be
5007 static.@Chg{Version=[3],New=[@AspectDefn{Bit_Order}],Old=[]}
5008
5009 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Bit_Order],
5010 Text=[@ChgAdded{Version=[3],Text=[Order of bit numbering in a
5011 @nt{record_representation_clause}.]}]}
5012
5013 @end{Description}
5014
5015 If Word_Size = Storage_Unit,
5016 the default bit ordering is implementation defined.
5017 If Word_Size > Storage_Unit,
5018 the default bit ordering is the same as the ordering of storage
5019 elements in a word, when interpreted as an
5020 integer.
5021 @IndexSee{Term=[byte sex],See=(ordering of storage elements in a word)}
5022 @ImplDef{If Word_Size = Storage_Unit,
5023 the default bit ordering.}
5024 @begin{Ramification}
5025 Consider machines whose Word_Size = 32,
5026 and whose Storage_Unit = 8.
5027 Assume the default bit ordering applies.
5028 On a machine with big-endian addresses,
5029 the most significant storage element of an integer is at the address of
5030 the integer.
5031 Therefore, bit zero of a storage element is the most significant bit.
5032 On a machine with little-endian addresses,
5033 the least significant storage element of an integer is at the address of
5034 the integer.
5035 Therefore, bit zero of a storage element is the least significant
5036 bit.
5037 @end{Ramification}
5038
5039 The storage place attributes of a
5040 component of a type are
5041 interpreted according to the bit ordering
5042 of the type.
5043 @begin{Ramification}
5044 This implies that the interpretation of the @nt{position},
5045 @nt{first_bit}, and @nt{last_bit} of a @nt{component_clause} of a
5046 @nt{record_representation_clause} obey the bit ordering given in a
5047 representation item.
5048 @end{Ramification}
5049 @end{StaticSem}
5050
5051 @begin{ImplAdvice}
5052 @Leading@PDefn2{Term=[recommended level of support], Sec=(bit ordering)}
5053 The recommended level of support for the nondefault bit ordering is:
5054 @begin{Itemize}
5055 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5056 @Chg{Version=[2],New=[The],Old=[If Word_Size = Storage_Unit, then
5057 the]} implementation should support the nondefault bit ordering
5058 in addition to the default bit ordering.
5059 @end{Itemize}
5060 @begin{Ramification}
5061 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5062 @Chg{Version=[2],New=[The],Old=[If Word_Size = Storage_Unit,
5063 the]} implementation should support both bit orderings.
5064 @Chg{Version=[2],New=[Implementations],Old=[We don't push for support of
5065 the nondefault bit ordering when Word_Size > Storage_Unit (except
5066 of course for upward compatibility with a preexisting implementation
5067 whose Ada 83 bit order did not correspond to the required Ada 95
5068 default bit order), because
5069 implementations]} are required to support storage positions that cross
5070 storage element boundaries when Word_Size > Storage_Unit@Chg{Version=[2],
5071 New=[ but the definition of the storage place attributes for the nondefault
5072 bit order ensures that such],Old=[. Such]} storage positions will @Chg{Version=[2],
5073 New=[not ],Old=[]}be split into two or three pieces@Chg{Version=[2],New=[. Thus,
5074 there is no significant implementation burden to supporting the nondefault
5075 bit order, given that the set of machine scalars is implementation-defined],
5076 Old=[ if the nondefault bit ordering is used, which could be onerous to
5077 support. However, if Word_Size = Storage_Unit,
5078 there might not be a natural bit ordering,
5079 but the splitting problem need not occur]}.
5080 @end{Ramification}
5081 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
5082 Text=[The recommended level of support for the nondefault bit ordering
5083 should be followed.]}]}
5084 @end{ImplAdvice}
5085
5086 @begin{Notes}
5087 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
5088 @ChgAdded{Version=[2],Text=[Bit_Order clauses make it possible to write
5089 @nt{record_representation_clause}s that can be ported between machines having
5090 different bit ordering. They do not guarantee transparent exchange of data
5091 between such machines.]}
5092 @end{Notes}
5093
5094 @begin{Extend83}
5095 @Defn{extensions to Ada 83}
5096 The Bit_Order attribute is new to Ada 95.
5097 @end{Extend83}
5098
5099 @begin{DiffWord95}
5100 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
5101 @ChgAdded{Version=[2],Text=[We now suggest that all implementations
5102 support the nondefault bit order.]}
5103 @end{Diffword95}
5104
5105
5106
5107 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
5108 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
5109 @LabeledClause{Change of Representation}
5110
5111 @begin{Intro}
5112 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
5113 @redundant[@Defn{change of representation}
5114 @Defn2{Term=[representation], Sec=(change of)}
5115 A @nt{type_conversion} (see @RefSecNum{Type Conversions})
5116 can be used to convert between two different
5117 representations of the same array or record.
5118 To convert an array from one representation to another,
5119 two array types need to be declared with
5120 matching component subtypes, and convertible index types.
5121 If one type has @Chg{Version=[3],New=[Pack],Old=[packing]}
5122 specified and the other does not,
5123 then explicit conversion can be used to pack or unpack an array.
5124
5125 To convert a record from one representation to another,
5126 two record types with a common ancestor type need to be declared,
5127 with no inherited subprograms. Distinct representations can then
5128 be specified for the record types, and explicit conversion between
5129 the types can be used to effect a change in representation.]
5130 @begin{Ramification}
5131 This technique does not work if the first type is an
5132 untagged type with user-defined primitive subprograms.
5133 It does not work at all for tagged types.
5134 @end{Ramification}
5135 @end{Intro}
5136
5137 @begin{Examples}
5138 @leading@keepnext@i{Example of change of representation:}
5139 @begin{Example}
5140 --@RI{ Packed_Descriptor and Descriptor are two different types}
5141 --@RI{ with identical characteristics, apart from their}
5142 --@RI{ representation}
5143
5144 @key[type] Descriptor @key[is]
5145 @key[record]
5146 --@RI{ components of a descriptor}
5147 @key[end] @key[record];
5148
5149 @key[type] Packed_Descriptor @key[is] @key[new] Descriptor;
5150
5151 @key[for] Packed_Descriptor @key[use]
5152 @key[record]
5153 --@RI{ component clauses for some or for all components}
5154 @key[end] @key[record];
5155
5156 @RI{-- Change of representation can now be accomplished by explicit type conversions:}
5157
5158 D : Descriptor;
5159 P : Packed_Descriptor;
5160
5161 P := Packed_Descriptor(D); --@RI{ pack D}
5162 D := Descriptor(P); --@RI{ unpack P}
5163 @end{Example}
5164 @end{Examples}
5165