Debian Codegraph @

gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst

raw
1 .. role:: switch(samp)
2
3 .. _Implementation_Defined_Pragmas:
4
5 ******************************
6 Implementation Defined Pragmas
7 ******************************
8
9 Ada defines a set of pragmas that can be used to supply additional
10 information to the compiler. These language defined pragmas are
11 implemented in GNAT and work as described in the Ada Reference Manual.
12
13 In addition, Ada allows implementations to define additional pragmas
14 whose meaning is defined by the implementation. GNAT provides a number
15 of these implementation-defined pragmas, which can be used to extend
16 and enhance the functionality of the compiler. This section of the GNAT
17 Reference Manual describes these additional pragmas.
18
19 Note that any program using these pragmas might not be portable to other
20 compilers (although GNAT implements this set of pragmas on all
21 platforms). Therefore if portability to other compilers is an important
22 consideration, the use of these pragmas should be minimized.
23
24 Pragma Abort_Defer
25 ==================
26
27 .. index:: Deferring aborts
28
29 Syntax:
30
31 .. code-block:: ada
32
33 pragma Abort_Defer;
34
35
36 This pragma must appear at the start of the statement sequence of a
37 handled sequence of statements (right after the ``begin``). It has
38 the effect of deferring aborts for the sequence of statements (but not
39 for the declarations or handlers, if any, associated with this statement
40 sequence). This can also be useful for adding a polling point in Ada code,
41 where asynchronous abort of tasks is checked when leaving the statement
42 sequence, and is lighter than, for example, using ``delay 0.0;``, since with
43 zero-cost exception handling, propagating exceptions (implicitly used to
44 implement task abort) cannot be done reliably in an asynchronous way.
45
46 An example of usage would be:
47
48 .. code-block:: ada
49
50 -- Add a polling point to check for task aborts
51
52 begin
53 pragma Abort_Defer;
54 end;
55
56 .. _Pragma-Abstract_State:
57
58 Pragma Abstract_State
59 =====================
60
61 Syntax:
62
63 .. code-block:: ada
64
65 pragma Abstract_State (ABSTRACT_STATE_LIST);
66
67 ABSTRACT_STATE_LIST ::=
68 null
69 | STATE_NAME_WITH_OPTIONS
70 | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
71
72 STATE_NAME_WITH_OPTIONS ::=
73 STATE_NAME
74 | (STATE_NAME with OPTION_LIST)
75
76 OPTION_LIST ::= OPTION {, OPTION}
77
78 OPTION ::=
79 SIMPLE_OPTION
80 | NAME_VALUE_OPTION
81
82 SIMPLE_OPTION ::= Ghost | Synchronous
83
84 NAME_VALUE_OPTION ::=
85 Part_Of => ABSTRACT_STATE
86 | External [=> EXTERNAL_PROPERTY_LIST]
87
88 EXTERNAL_PROPERTY_LIST ::=
89 EXTERNAL_PROPERTY
90 | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
91
92 EXTERNAL_PROPERTY ::=
93 Async_Readers [=> static_boolean_EXPRESSION]
94 | Async_Writers [=> static_boolean_EXPRESSION]
95 | Effective_Reads [=> static_boolean_EXPRESSION]
96 | Effective_Writes [=> static_boolean_EXPRESSION]
97 others => static_boolean_EXPRESSION
98
99 STATE_NAME ::= defining_identifier
100
101 ABSTRACT_STATE ::= name
102
103 For the semantics of this pragma, see the entry for aspect ``Abstract_State`` in
104 the SPARK 2014 Reference Manual, section 7.1.4.
105
106 Pragma Ada_83
107 =============
108
109 Syntax:
110
111 .. code-block:: ada
112
113 pragma Ada_83;
114
115
116 A configuration pragma that establishes Ada 83 mode for the unit to
117 which it applies, regardless of the mode set by the command line
118 switches. In Ada 83 mode, GNAT attempts to be as compatible with
119 the syntax and semantics of Ada 83, as defined in the original Ada
120 83 Reference Manual as possible. In particular, the keywords added by Ada 95
121 and Ada 2005 are not recognized, optional package bodies are allowed,
122 and generics may name types with unknown discriminants without using
123 the ``(<>)`` notation. In addition, some but not all of the additional
124 restrictions of Ada 83 are enforced.
125
126 Ada 83 mode is intended for two purposes. Firstly, it allows existing
127 Ada 83 code to be compiled and adapted to GNAT with less effort.
128 Secondly, it aids in keeping code backwards compatible with Ada 83.
129 However, there is no guarantee that code that is processed correctly
130 by GNAT in Ada 83 mode will in fact compile and execute with an Ada
131 83 compiler, since GNAT does not enforce all the additional checks
132 required by Ada 83.
133
134 Pragma Ada_95
135 =============
136
137 Syntax:
138
139 .. code-block:: ada
140
141 pragma Ada_95;
142
143
144 A configuration pragma that establishes Ada 95 mode for the unit to which
145 it applies, regardless of the mode set by the command line switches.
146 This mode is set automatically for the ``Ada`` and ``System``
147 packages and their children, so you need not specify it in these
148 contexts. This pragma is useful when writing a reusable component that
149 itself uses Ada 95 features, but which is intended to be usable from
150 either Ada 83 or Ada 95 programs.
151
152 Pragma Ada_05
153 =============
154
155 Syntax:
156
157 .. code-block:: ada
158
159 pragma Ada_05;
160 pragma Ada_05 (local_NAME);
161
162
163 A configuration pragma that establishes Ada 2005 mode for the unit to which
164 it applies, regardless of the mode set by the command line switches.
165 This pragma is useful when writing a reusable component that
166 itself uses Ada 2005 features, but which is intended to be usable from
167 either Ada 83 or Ada 95 programs.
168
169 The one argument form (which is not a configuration pragma)
170 is used for managing the transition from
171 Ada 95 to Ada 2005 in the run-time library. If an entity is marked
172 as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
173 mode will generate a warning. In addition, in Ada_83 or Ada_95
174 mode, a preference rule is established which does not choose
175 such an entity unless it is unambiguously specified. This avoids
176 extra subprograms marked this way from generating ambiguities in
177 otherwise legal pre-Ada_2005 programs. The one argument form is
178 intended for exclusive use in the GNAT run-time library.
179
180 Pragma Ada_2005
181 ===============
182
183 Syntax:
184
185 .. code-block:: ada
186
187 pragma Ada_2005;
188
189
190 This configuration pragma is a synonym for pragma Ada_05 and has the
191 same syntax and effect.
192
193 Pragma Ada_12
194 =============
195
196 Syntax:
197
198 .. code-block:: ada
199
200 pragma Ada_12;
201 pragma Ada_12 (local_NAME);
202
203
204 A configuration pragma that establishes Ada 2012 mode for the unit to which
205 it applies, regardless of the mode set by the command line switches.
206 This mode is set automatically for the ``Ada`` and ``System``
207 packages and their children, so you need not specify it in these
208 contexts. This pragma is useful when writing a reusable component that
209 itself uses Ada 2012 features, but which is intended to be usable from
210 Ada 83, Ada 95, or Ada 2005 programs.
211
212 The one argument form, which is not a configuration pragma,
213 is used for managing the transition from Ada
214 2005 to Ada 2012 in the run-time library. If an entity is marked
215 as Ada_2012 only, then referencing the entity in any pre-Ada_2012
216 mode will generate a warning. In addition, in any pre-Ada_2012
217 mode, a preference rule is established which does not choose
218 such an entity unless it is unambiguously specified. This avoids
219 extra subprograms marked this way from generating ambiguities in
220 otherwise legal pre-Ada_2012 programs. The one argument form is
221 intended for exclusive use in the GNAT run-time library.
222
223 Pragma Ada_2012
224 ===============
225
226 Syntax:
227
228 .. code-block:: ada
229
230 pragma Ada_2012;
231
232
233 This configuration pragma is a synonym for pragma Ada_12 and has the
234 same syntax and effect.
235
236 Pragma Ada_2022
237 ===============
238
239 Syntax:
240
241 .. code-block:: ada
242
243 pragma Ada_2022;
244 pragma Ada_2022 (local_NAME);
245
246
247 A configuration pragma that establishes Ada 2022 mode for the unit to which
248 it applies, regardless of the mode set by the command line switches.
249 This mode is set automatically for the ``Ada`` and ``System``
250 packages and their children, so you need not specify it in these
251 contexts. This pragma is useful when writing a reusable component that
252 itself uses Ada 2022 features, but which is intended to be usable from
253 Ada 83, Ada 95, Ada 2005 or Ada 2012 programs.
254
255 The one argument form, which is not a configuration pragma,
256 is used for managing the transition from Ada
257 2012 to Ada 2022 in the run-time library. If an entity is marked
258 as Ada_2022 only, then referencing the entity in any pre-Ada_2022
259 mode will generate a warning. In addition, in any pre-Ada_2012
260 mode, a preference rule is established which does not choose
261 such an entity unless it is unambiguously specified. This avoids
262 extra subprograms marked this way from generating ambiguities in
263 otherwise legal pre-Ada_2022 programs. The one argument form is
264 intended for exclusive use in the GNAT run-time library.
265
266 Pragma Aggregate_Individually_Assign
267 ====================================
268
269 Syntax:
270
271 .. code-block:: ada
272
273 pragma Aggregate_Individually_Assign;
274
275 Where possible, GNAT will store the binary representation of a record aggregate
276 in memory for space and performance reasons. This configuration pragma changes
277 this behavior so that record aggregates are instead always converted into
278 individual assignment statements.
279
280
281 Pragma Allow_Integer_Address
282 ============================
283
284 Syntax:
285
286 .. code-block:: ada
287
288 pragma Allow_Integer_Address;
289
290
291 In almost all versions of GNAT, ``System.Address`` is a private
292 type in accordance with the implementation advice in the RM. This
293 means that integer values,
294 in particular integer literals, are not allowed as address values.
295 If the configuration pragma
296 ``Allow_Integer_Address`` is given, then integer expressions may
297 be used anywhere a value of type ``System.Address`` is required.
298 The effect is to introduce an implicit unchecked conversion from the
299 integer value to type ``System.Address``. The reverse case of using
300 an address where an integer type is required is handled analogously.
301 The following example compiles without errors:
302
303
304 .. code-block:: ada
305
306 pragma Allow_Integer_Address;
307 with System; use System;
308 package AddrAsInt is
309 X : Integer;
310 Y : Integer;
311 for X'Address use 16#1240#;
312 for Y use at 16#3230#;
313 m : Address := 16#4000#;
314 n : constant Address := 4000;
315 p : constant Address := Address (X + Y);
316 v : Integer := y'Address;
317 w : constant Integer := Integer (Y'Address);
318 type R is new integer;
319 RR : R := 1000;
320 Z : Integer;
321 for Z'Address use RR;
322 end AddrAsInt;
323
324
325 Note that pragma ``Allow_Integer_Address`` is ignored if ``System.Address``
326 is not a private type. In implementations of ``GNAT`` where
327 System.Address is a visible integer type,
328 this pragma serves no purpose but is ignored
329 rather than rejected to allow common sets of sources to be used
330 in the two situations.
331
332 .. _Pragma-Always_Terminates:
333
334 Pragma Always_Terminates
335 ========================
336
337 Syntax:
338
339 .. code-block:: ada
340
341 pragma Always_Terminates [ (boolean_EXPRESSION) ];
342
343 For the semantics of this pragma, see the entry for aspect ``Always_Terminates``
344 in the SPARK 2014 Reference Manual, section 6.1.11.
345
346 .. _Pragma-Annotate:
347
348 Pragma Annotate
349 ===============
350
351 Syntax::
352
353 pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}] [, entity => local_NAME]);
354
355 ARG ::= NAME | EXPRESSION
356
357
358 This pragma is used to annotate programs. IDENTIFIER identifies
359 the type of annotation. GNAT verifies that it is an identifier, but does
360 not otherwise analyze it. The second optional identifier is also left
361 unanalyzed, and by convention is used to control the action of the tool to
362 which the annotation is addressed. The remaining ARG arguments
363 can be either string literals or more generally expressions.
364 String literals (and concatenations of string literals) are assumed to be
365 either of type
366 ``Standard.String`` or else ``Wide_String`` or ``Wide_Wide_String``
367 depending on the character literals they contain.
368 All other kinds of arguments are analyzed as expressions, and must be
369 unambiguous. The last argument if present must have the identifier
370 ``Entity`` and GNAT verifies that a local name is given.
371
372 The analyzed pragma is retained in the tree, but not otherwise processed
373 by any part of the GNAT compiler, except to generate corresponding note
374 lines in the generated ALI file. For the format of these note lines, see
375 the compiler source file lib-writ.ads. This pragma is intended for use by
376 external tools, including ASIS. The use of pragma Annotate does not
377 affect the compilation process in any way. This pragma may be used as
378 a configuration pragma.
379
380 Pragma Assert
381 =============
382
383 Syntax::
384
385 pragma Assert (
386 boolean_EXPRESSION
387 [, string_EXPRESSION]);
388
389
390 The effect of this pragma depends on whether the corresponding command
391 line switch is set to activate assertions. The pragma expands into code
392 equivalent to the following:
393
394 .. code-block:: ada
395
396 if assertions-enabled then
397 if not boolean_EXPRESSION then
398 System.Assertions.Raise_Assert_Failure
399 (string_EXPRESSION);
400 end if;
401 end if;
402
403
404 The string argument, if given, is the message that will be associated
405 with the exception occurrence if the exception is raised. If no second
406 argument is given, the default message is ``file``:``nnn``,
407 where ``file`` is the name of the source file containing the assert,
408 and ``nnn`` is the line number of the assert.
409
410 Note that, as with the ``if`` statement to which it is equivalent, the
411 type of the expression is either ``Standard.Boolean``, or any type derived
412 from this standard type.
413
414 Assert checks can be either checked or ignored. By default they are ignored.
415 They will be checked if either the command line switch *-gnata* is
416 used, or if an ``Assertion_Policy`` or ``Check_Policy`` pragma is used
417 to enable ``Assert_Checks``.
418
419 If assertions are ignored, then there
420 is no run-time effect (and in particular, any side effects from the
421 expression will not occur at run time). (The expression is still
422 analyzed at compile time, and may cause types to be frozen if they are
423 mentioned here for the first time).
424
425 If assertions are checked, then the given expression is tested, and if
426 it is ``False`` then ``System.Assertions.Raise_Assert_Failure`` is called
427 which results in the raising of ``Assert_Failure`` with the given message.
428
429 You should generally avoid side effects in the expression arguments of
430 this pragma, because these side effects will turn on and off with the
431 setting of the assertions mode, resulting in assertions that have an
432 effect on the program. However, the expressions are analyzed for
433 semantic correctness whether or not assertions are enabled, so turning
434 assertions on and off cannot affect the legality of a program.
435
436 Note that the implementation defined policy ``DISABLE``, given in a
437 pragma ``Assertion_Policy``, can be used to suppress this semantic analysis.
438
439 Note: this is a standard language-defined pragma in versions
440 of Ada from 2005 on. In GNAT, it is implemented in all versions
441 of Ada, and the DISABLE policy is an implementation-defined
442 addition.
443
444 Pragma Assert_And_Cut
445 =====================
446
447 Syntax::
448
449 pragma Assert_And_Cut (
450 boolean_EXPRESSION
451 [, string_EXPRESSION]);
452
453
454 The effect of this pragma is identical to that of pragma ``Assert``,
455 except that in an ``Assertion_Policy`` pragma, the identifier
456 ``Assert_And_Cut`` is used to control whether it is ignored or checked
457 (or disabled).
458
459 The intention is that this be used within a subprogram when the
460 given test expresion sums up all the work done so far in the
461 subprogram, so that the rest of the subprogram can be verified
462 (informally or formally) using only the entry preconditions,
463 and the expression in this pragma. This allows dividing up
464 a subprogram into sections for the purposes of testing or
465 formal verification. The pragma also serves as useful
466 documentation.
467
468 Pragma Assertion_Policy
469 =======================
470
471 Syntax::
472
473 pragma Assertion_Policy (CHECK | DISABLE | IGNORE | SUPPRESSIBLE);
474
475 pragma Assertion_Policy (
476 ASSERTION_KIND => POLICY_IDENTIFIER
477 {, ASSERTION_KIND => POLICY_IDENTIFIER});
478
479 ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
480
481 RM_ASSERTION_KIND ::= Assert |
482 Static_Predicate |
483 Dynamic_Predicate |
484 Pre |
485 Pre'Class |
486 Post |
487 Post'Class |
488 Type_Invariant |
489 Type_Invariant'Class |
490 Default_Initial_Condition
491
492 ID_ASSERTION_KIND ::= Assertions |
493 Assert_And_Cut |
494 Assume |
495 Contract_Cases |
496 Debug |
497 Ghost |
498 Initial_Condition |
499 Invariant |
500 Invariant'Class |
501 Loop_Invariant |
502 Loop_Variant |
503 Postcondition |
504 Precondition |
505 Predicate |
506 Refined_Post |
507 Statement_Assertions |
508 Subprogram_Variant
509
510 POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
511
512
513 This is a standard Ada 2012 pragma that is available as an
514 implementation-defined pragma in earlier versions of Ada.
515 The assertion kinds ``RM_ASSERTION_KIND`` are those defined in
516 the Ada standard. The assertion kinds ``ID_ASSERTION_KIND``
517 are implementation defined additions recognized by the GNAT compiler.
518
519 The pragma applies in both cases to pragmas and aspects with matching
520 names, e.g. ``Pre`` applies to the Pre aspect, and ``Precondition``
521 applies to both the ``Precondition`` pragma
522 and the aspect ``Precondition``. Note that the identifiers for
523 pragmas Pre_Class and Post_Class are Pre'Class and Post'Class (not
524 Pre_Class and Post_Class), since these pragmas are intended to be
525 identical to the corresponding aspects.
526
527 If the policy is ``CHECK``, then assertions are enabled, i.e.
528 the corresponding pragma or aspect is activated.
529 If the policy is ``IGNORE``, then assertions are ignored, i.e.
530 the corresponding pragma or aspect is deactivated.
531 This pragma overrides the effect of the *-gnata* switch on the
532 command line.
533 If the policy is ``SUPPRESSIBLE``, then assertions are enabled by default,
534 however, if the *-gnatp* switch is specified all assertions are ignored.
535
536 The implementation defined policy ``DISABLE`` is like
537 ``IGNORE`` except that it completely disables semantic
538 checking of the corresponding pragma or aspect. This is
539 useful when the pragma or aspect argument references subprograms
540 in a with'ed package which is replaced by a dummy package
541 for the final build.
542
543 The implementation defined assertion kind ``Assertions`` applies to all
544 assertion kinds. The form with no assertion kind given implies this
545 choice, so it applies to all assertion kinds (RM defined, and
546 implementation defined).
547
548 The implementation defined assertion kind ``Statement_Assertions``
549 applies to ``Assert``, ``Assert_And_Cut``,
550 ``Assume``, ``Loop_Invariant``, and ``Loop_Variant``.
551
552 Pragma Assume
553 =============
554
555 Syntax:
556
557 ::
558
559 pragma Assume (
560 boolean_EXPRESSION
561 [, string_EXPRESSION]);
562
563
564 The effect of this pragma is identical to that of pragma ``Assert``,
565 except that in an ``Assertion_Policy`` pragma, the identifier
566 ``Assume`` is used to control whether it is ignored or checked
567 (or disabled).
568
569 The intention is that this be used for assumptions about the
570 external environment. So you cannot expect to verify formally
571 or informally that the condition is met, this must be
572 established by examining things outside the program itself.
573 For example, we may have code that depends on the size of
574 ``Long_Long_Integer`` being at least 64. So we could write:
575
576 .. code-block:: ada
577
578 pragma Assume (Long_Long_Integer'Size >= 64);
579
580
581 This assumption cannot be proved from the program itself,
582 but it acts as a useful run-time check that the assumption
583 is met, and documents the need to ensure that it is met by
584 reference to information outside the program.
585
586 Pragma Assume_No_Invalid_Values
587 ===============================
588 .. index:: Invalid representations
589
590 .. index:: Invalid values
591
592 Syntax:
593
594 .. code-block:: ada
595
596 pragma Assume_No_Invalid_Values (On | Off);
597
598
599 This is a configuration pragma that controls the assumptions made by the
600 compiler about the occurrence of invalid representations (invalid values)
601 in the code.
602
603 The default behavior (corresponding to an Off argument for this pragma), is
604 to assume that values may in general be invalid unless the compiler can
605 prove they are valid. Consider the following example:
606
607 .. code-block:: ada
608
609 V1 : Integer range 1 .. 10;
610 V2 : Integer range 11 .. 20;
611 ...
612 for J in V2 .. V1 loop
613 ...
614 end loop;
615
616
617 if V1 and V2 have valid values, then the loop is known at compile
618 time not to execute since the lower bound must be greater than the
619 upper bound. However in default mode, no such assumption is made,
620 and the loop may execute. If ``Assume_No_Invalid_Values (On)``
621 is given, the compiler will assume that any occurrence of a variable
622 other than in an explicit ``'Valid`` test always has a valid
623 value, and the loop above will be optimized away.
624
625 The use of ``Assume_No_Invalid_Values (On)`` is appropriate if
626 you know your code is free of uninitialized variables and other
627 possible sources of invalid representations, and may result in
628 more efficient code. A program that accesses an invalid representation
629 with this pragma in effect is erroneous, so no guarantees can be made
630 about its behavior.
631
632 It is peculiar though permissible to use this pragma in conjunction
633 with validity checking (-gnatVa). In such cases, accessing invalid
634 values will generally give an exception, though formally the program
635 is erroneous so there are no guarantees that this will always be the
636 case, and it is recommended that these two options not be used together.
637
638 .. _Pragma-Async_Readers:
639
640 Pragma Async_Readers
641 ====================
642
643 Syntax:
644
645 .. code-block:: ada
646
647 pragma Async_Readers [ (static_boolean_EXPRESSION) ];
648
649 For the semantics of this pragma, see the entry for aspect ``Async_Readers`` in
650 the SPARK 2014 Reference Manual, section 7.1.2.
651
652 .. _Pragma-Async_Writers:
653
654 Pragma Async_Writers
655 ====================
656
657 Syntax:
658
659 .. code-block:: ada
660
661 pragma Async_Writers [ (static_boolean_EXPRESSION) ];
662
663 For the semantics of this pragma, see the entry for aspect ``Async_Writers`` in
664 the SPARK 2014 Reference Manual, section 7.1.2.
665
666 Pragma Attribute_Definition
667 ===========================
668
669 Syntax:
670
671 ::
672
673 pragma Attribute_Definition
674 ([Attribute =>] ATTRIBUTE_DESIGNATOR,
675 [Entity =>] LOCAL_NAME,
676 [Expression =>] EXPRESSION | NAME);
677
678
679 If ``Attribute`` is a known attribute name, this pragma is equivalent to
680 the attribute definition clause:
681
682
683 .. code-block:: ada
684
685 for Entity'Attribute use Expression;
686
687
688 If ``Attribute`` is not a recognized attribute name, the pragma is
689 ignored, and a warning is emitted. This allows source
690 code to be written that takes advantage of some new attribute, while remaining
691 compilable with earlier compilers.
692
693 Pragma C_Pass_By_Copy
694 =====================
695 .. index:: Passing by copy
696
697
698 Syntax:
699
700 ::
701
702 pragma C_Pass_By_Copy
703 ([Max_Size =>] static_integer_EXPRESSION);
704
705
706 Normally the default mechanism for passing C convention records to C
707 convention subprograms is to pass them by reference, as suggested by RM
708 B.3(69). Use the configuration pragma ``C_Pass_By_Copy`` to change
709 this default, by requiring that record formal parameters be passed by
710 copy if all of the following conditions are met:
711
712 *
713 The size of the record type does not exceed the value specified for
714 ``Max_Size``.
715 *
716 The record type has ``Convention C``.
717 *
718 The formal parameter has this record type, and the subprogram has a
719 foreign (non-Ada) convention.
720
721 If these conditions are met the argument is passed by copy; i.e., in a
722 manner consistent with what C expects if the corresponding formal in the
723 C prototype is a struct (rather than a pointer to a struct).
724
725 You can also pass records by copy by specifying the convention
726 ``C_Pass_By_Copy`` for the record type, or by using the extended
727 ``Import`` and ``Export`` pragmas, which allow specification of
728 passing mechanisms on a parameter by parameter basis.
729
730 Pragma Check
731 ============
732 .. index:: Assertions
733
734 .. index:: Named assertions
735
736
737 Syntax:
738
739 ::
740
741 pragma Check (
742 [Name =>] CHECK_KIND,
743 [Check =>] Boolean_EXPRESSION
744 [, [Message =>] string_EXPRESSION] );
745
746 CHECK_KIND ::= IDENTIFIER |
747 Pre'Class |
748 Post'Class |
749 Type_Invariant'Class |
750 Invariant'Class
751
752
753 This pragma is similar to the predefined pragma ``Assert`` except that an
754 extra identifier argument is present. In conjunction with pragma
755 ``Check_Policy``, this can be used to define groups of assertions that can
756 be independently controlled. The identifier ``Assertion`` is special, it
757 refers to the normal set of pragma ``Assert`` statements.
758
759 Checks introduced by this pragma are normally deactivated by default. They can
760 be activated either by the command line option *-gnata*, which turns on
761 all checks, or individually controlled using pragma ``Check_Policy``.
762
763 The identifiers ``Assertions`` and ``Statement_Assertions`` are not
764 permitted as check kinds, since this would cause confusion with the use
765 of these identifiers in ``Assertion_Policy`` and ``Check_Policy``
766 pragmas, where they are used to refer to sets of assertions.
767
768 Pragma Check_Float_Overflow
769 ===========================
770 .. index:: Floating-point overflow
771
772
773 Syntax:
774
775 .. code-block:: ada
776
777 pragma Check_Float_Overflow;
778
779
780 In Ada, the predefined floating-point types (``Short_Float``,
781 ``Float``, ``Long_Float``, ``Long_Long_Float``) are
782 defined to be *unconstrained*. This means that even though each
783 has a well-defined base range, an operation that delivers a result
784 outside this base range is not required to raise an exception.
785 This implementation permission accommodates the notion
786 of infinities in IEEE floating-point, and corresponds to the
787 efficient execution mode on most machines. GNAT will not raise
788 overflow exceptions on these machines; instead it will generate
789 infinities and NaN's as defined in the IEEE standard.
790
791 Generating infinities, although efficient, is not always desirable.
792 Often the preferable approach is to check for overflow, even at the
793 (perhaps considerable) expense of run-time performance.
794 This can be accomplished by defining your own constrained floating-point subtypes -- i.e., by supplying explicit
795 range constraints -- and indeed such a subtype
796 can have the same base range as its base type. For example:
797
798
799 .. code-block:: ada
800
801 subtype My_Float is Float range Float'Range;
802
803
804 Here ``My_Float`` has the same range as
805 ``Float`` but is constrained, so operations on
806 ``My_Float`` values will be checked for overflow
807 against this range.
808
809 This style will achieve the desired goal, but
810 it is often more convenient to be able to simply use
811 the standard predefined floating-point types as long
812 as overflow checking could be guaranteed.
813 The ``Check_Float_Overflow``
814 configuration pragma achieves this effect. If a unit is compiled
815 subject to this configuration pragma, then all operations
816 on predefined floating-point types including operations on
817 base types of these floating-point types will be treated as
818 though those types were constrained, and overflow checks
819 will be generated. The ``Constraint_Error``
820 exception is raised if the result is out of range.
821
822 This mode can also be set by use of the compiler
823 switch *-gnateF*.
824
825 Pragma Check_Name
826 =================
827 .. index:: Defining check names
828
829 .. index:: Check names, defining
830
831
832 Syntax:
833
834 .. code-block:: ada
835
836 pragma Check_Name (check_name_IDENTIFIER);
837
838
839 This is a configuration pragma that defines a new implementation
840 defined check name (unless IDENTIFIER matches one of the predefined
841 check names, in which case the pragma has no effect). Check names
842 are global to a partition, so if two or more configuration pragmas
843 are present in a partition mentioning the same name, only one new
844 check name is introduced.
845
846 An implementation defined check name introduced with this pragma may
847 be used in only three contexts: ``pragma Suppress``,
848 ``pragma Unsuppress``,
849 and as the prefix of a ``Check_Name'Enabled`` attribute reference. For
850 any of these three cases, the check name must be visible. A check
851 name is visible if it is in the configuration pragmas applying to
852 the current unit, or if it appears at the start of any unit that
853 is part of the dependency set of the current unit (e.g., units that
854 are mentioned in ``with`` clauses).
855
856 Check names introduced by this pragma are subject to control by compiler
857 switches (in particular -gnatp) in the usual manner.
858
859 Pragma Check_Policy
860 ===================
861 .. index:: Controlling assertions
862
863 .. index:: Assertions, control
864
865 .. index:: Check pragma control
866
867 .. index:: Named assertions
868
869
870 Syntax:
871
872 ::
873
874 pragma Check_Policy
875 ([Name =>] CHECK_KIND,
876 [Policy =>] POLICY_IDENTIFIER);
877
878 pragma Check_Policy (
879 CHECK_KIND => POLICY_IDENTIFIER
880 {, CHECK_KIND => POLICY_IDENTIFIER});
881
882 ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
883
884 CHECK_KIND ::= IDENTIFIER |
885 Pre'Class |
886 Post'Class |
887 Type_Invariant'Class |
888 Invariant'Class
889
890 The identifiers Name and Policy are not allowed as CHECK_KIND values. This
891 avoids confusion between the two possible syntax forms for this pragma.
892
893 POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
894
895
896 This pragma is used to set the checking policy for assertions (specified
897 by aspects or pragmas), the ``Debug`` pragma, or additional checks
898 to be checked using the ``Check`` pragma. It may appear either as
899 a configuration pragma, or within a declarative part of package. In the
900 latter case, it applies from the point where it appears to the end of
901 the declarative region (like pragma ``Suppress``).
902
903 The ``Check_Policy`` pragma is similar to the
904 predefined ``Assertion_Policy`` pragma,
905 and if the check kind corresponds to one of the assertion kinds that
906 are allowed by ``Assertion_Policy``, then the effect is identical.
907
908 If the first argument is Debug, then the policy applies to Debug pragmas,
909 disabling their effect if the policy is ``OFF``, ``DISABLE``, or
910 ``IGNORE``, and allowing them to execute with normal semantics if
911 the policy is ``ON`` or ``CHECK``. In addition if the policy is
912 ``DISABLE``, then the procedure call in ``Debug`` pragmas will
913 be totally ignored and not analyzed semantically.
914
915 Finally the first argument may be some other identifier than the above
916 possibilities, in which case it controls a set of named assertions
917 that can be checked using pragma ``Check``. For example, if the pragma:
918
919
920 .. code-block:: ada
921
922 pragma Check_Policy (Critical_Error, OFF);
923
924
925 is given, then subsequent ``Check`` pragmas whose first argument is also
926 ``Critical_Error`` will be disabled.
927
928 The check policy is ``OFF`` to turn off corresponding checks, and ``ON``
929 to turn on corresponding checks. The default for a set of checks for which no
930 ``Check_Policy`` is given is ``OFF`` unless the compiler switch
931 *-gnata* is given, which turns on all checks by default.
932
933 The check policy settings ``CHECK`` and ``IGNORE`` are recognized
934 as synonyms for ``ON`` and ``OFF``. These synonyms are provided for
935 compatibility with the standard ``Assertion_Policy`` pragma. The check
936 policy setting ``DISABLE`` causes the second argument of a corresponding
937 ``Check`` pragma to be completely ignored and not analyzed.
938
939 Pragma Comment
940 ==============
941
942 Syntax:
943
944
945 .. code-block:: ada
946
947 pragma Comment (static_string_EXPRESSION);
948
949
950 This is almost identical in effect to pragma ``Ident``. It allows the
951 placement of a comment into the object file and hence into the
952 executable file if the operating system permits such usage. The
953 difference is that ``Comment``, unlike ``Ident``, has
954 no limitations on placement of the pragma (it can be placed
955 anywhere in the main source unit), and if more than one pragma
956 is used, all comments are retained.
957
958 Pragma Common_Object
959 ====================
960
961 Syntax:
962
963
964 ::
965
966 pragma Common_Object (
967 [Internal =>] LOCAL_NAME
968 [, [External =>] EXTERNAL_SYMBOL]
969 [, [Size =>] EXTERNAL_SYMBOL] );
970
971 EXTERNAL_SYMBOL ::=
972 IDENTIFIER
973 | static_string_EXPRESSION
974
975
976 This pragma enables the shared use of variables stored in overlaid
977 linker areas corresponding to the use of ``COMMON``
978 in Fortran. The single
979 object ``LOCAL_NAME`` is assigned to the area designated by
980 the ``External`` argument.
981 You may define a record to correspond to a series
982 of fields. The ``Size`` argument
983 is syntax checked in GNAT, but otherwise ignored.
984
985 ``Common_Object`` is not supported on all platforms. If no
986 support is available, then the code generator will issue a message
987 indicating that the necessary attribute for implementation of this
988 pragma is not available.
989
990 .. _Compile_Time_Error:
991
992 Pragma Compile_Time_Error
993 =========================
994
995 Syntax:
996
997
998 .. code-block:: ada
999
1000 pragma Compile_Time_Error
1001 (boolean_EXPRESSION, static_string_EXPRESSION);
1002
1003
1004 This pragma can be used to generate additional compile time
1005 error messages. It
1006 is particularly useful in generics, where errors can be issued for
1007 specific problematic instantiations. The first parameter is a boolean
1008 expression. The pragma ensures that the value of an expression
1009 is known at compile time, and has the value False. The set of expressions
1010 whose values are known at compile time includes all static boolean
1011 expressions, and also other values which the compiler can determine
1012 at compile time (e.g., the size of a record type set by an explicit
1013 size representation clause, or the value of a variable which was
1014 initialized to a constant and is known not to have been modified).
1015 If these conditions are not met, an error message is generated using
1016 the value given as the second argument. This string value may contain
1017 embedded ASCII.LF characters to break the message into multiple lines.
1018
1019 Pragma Compile_Time_Warning
1020 ===========================
1021
1022 Syntax:
1023
1024
1025 .. code-block:: ada
1026
1027 pragma Compile_Time_Warning
1028 (boolean_EXPRESSION, static_string_EXPRESSION);
1029
1030
1031 Same as pragma Compile_Time_Error, except a warning is issued instead
1032 of an error message. If switch *-gnatw_C* is used, a warning is only issued
1033 if the value of the expression is known to be True at compile time, not when
1034 the value of the expression is not known at compile time.
1035 Note that if this pragma is used in a package that
1036 is with'ed by a client, the client will get the warning even though it
1037 is issued by a with'ed package (normally warnings in with'ed units are
1038 suppressed, but this is a special exception to that rule).
1039
1040 One typical use is within a generic where compile time known characteristics
1041 of formal parameters are tested, and warnings given appropriately. Another use
1042 with a first parameter of True is to warn a client about use of a package,
1043 for example that it is not fully implemented.
1044
1045 In previous versions of the compiler, combining *-gnatwe* with
1046 Compile_Time_Warning resulted in a fatal error. Now the compiler always emits
1047 a warning. You can use :ref:`Compile_Time_Error` to force the generation of
1048 an error.
1049
1050 Pragma Complete_Representation
1051 ==============================
1052
1053 Syntax:
1054
1055
1056 .. code-block:: ada
1057
1058 pragma Complete_Representation;
1059
1060
1061 This pragma must appear immediately within a record representation
1062 clause. Typical placements are before the first component clause
1063 or after the last component clause. The effect is to give an error
1064 message if any component is missing a component clause. This pragma
1065 may be used to ensure that a record representation clause is
1066 complete, and that this invariant is maintained if fields are
1067 added to the record in the future.
1068
1069 Pragma Complex_Representation
1070 =============================
1071
1072 Syntax:
1073
1074
1075 ::
1076
1077 pragma Complex_Representation
1078 ([Entity =>] LOCAL_NAME);
1079
1080
1081 The ``Entity`` argument must be the name of a record type which has
1082 two fields of the same floating-point type. The effect of this pragma is
1083 to force gcc to use the special internal complex representation form for
1084 this record, which may be more efficient. Note that this may result in
1085 the code for this type not conforming to standard ABI (application
1086 binary interface) requirements for the handling of record types. For
1087 example, in some environments, there is a requirement for passing
1088 records by pointer, and the use of this pragma may result in passing
1089 this type in floating-point registers.
1090
1091 Pragma Component_Alignment
1092 ==========================
1093 .. index:: Alignments of components
1094 .. index:: Pragma Component_Alignment
1095
1096
1097 Syntax:
1098
1099 ::
1100
1101 pragma Component_Alignment (
1102 [Form =>] ALIGNMENT_CHOICE
1103 [, [Name =>] type_LOCAL_NAME]);
1104
1105 ALIGNMENT_CHOICE ::=
1106 Component_Size
1107 | Component_Size_4
1108 | Storage_Unit
1109 | Default
1110
1111
1112 Specifies the alignment of components in array or record types.
1113 The meaning of the ``Form`` argument is as follows:
1114
1115
1116 .. index:: Component_Size (in pragma Component_Alignment)
1117
1118 *Component_Size*
1119 Aligns scalar components and subcomponents of the array or record type
1120 on boundaries appropriate to their inherent size (naturally
1121 aligned). For example, 1-byte components are aligned on byte boundaries,
1122 2-byte integer components are aligned on 2-byte boundaries, 4-byte
1123 integer components are aligned on 4-byte boundaries and so on. These
1124 alignment rules correspond to the normal rules for C compilers on all
1125 machines except the VAX.
1126
1127 .. index:: Component_Size_4 (in pragma Component_Alignment)
1128
1129 *Component_Size_4*
1130 Naturally aligns components with a size of four or fewer
1131 bytes. Components that are larger than 4 bytes are placed on the next
1132 4-byte boundary.
1133
1134 .. index:: Storage_Unit (in pragma Component_Alignment)
1135
1136 *Storage_Unit*
1137 Specifies that array or record components are byte aligned, i.e.,
1138 aligned on boundaries determined by the value of the constant
1139 ``System.Storage_Unit``.
1140
1141 .. index:: Default (in pragma Component_Alignment)
1142
1143 *Default*
1144 Specifies that array or record components are aligned on default
1145 boundaries, appropriate to the underlying hardware or operating system or
1146 both. The ``Default`` choice is the same as ``Component_Size`` (natural
1147 alignment).
1148
1149 If the ``Name`` parameter is present, ``type_LOCAL_NAME`` must
1150 refer to a local record or array type, and the specified alignment
1151 choice applies to the specified type. The use of
1152 ``Component_Alignment`` together with a pragma ``Pack`` causes the
1153 ``Component_Alignment`` pragma to be ignored. The use of
1154 ``Component_Alignment`` together with a record representation clause
1155 is only effective for fields not specified by the representation clause.
1156
1157 If the ``Name`` parameter is absent, the pragma can be used as either
1158 a configuration pragma, in which case it applies to one or more units in
1159 accordance with the normal rules for configuration pragmas, or it can be
1160 used within a declarative part, in which case it applies to types that
1161 are declared within this declarative part, or within any nested scope
1162 within this declarative part. In either case it specifies the alignment
1163 to be applied to any record or array type which has otherwise standard
1164 representation.
1165
1166 If the alignment for a record or array type is not specified (using
1167 pragma ``Pack``, pragma ``Component_Alignment``, or a record rep
1168 clause), the GNAT uses the default alignment as described previously.
1169
1170 .. _Pragma-Constant_After_Elaboration:
1171
1172 Pragma Constant_After_Elaboration
1173 =================================
1174
1175 Syntax:
1176
1177 .. code-block:: ada
1178
1179 pragma Constant_After_Elaboration [ (static_boolean_EXPRESSION) ];
1180
1181 For the semantics of this pragma, see the entry for aspect
1182 ``Constant_After_Elaboration`` in the SPARK 2014 Reference Manual, section 3.3.1.
1183
1184 .. _Pragma-Contract_Cases:
1185
1186 Pragma Contract_Cases
1187 =====================
1188 .. index:: Contract cases
1189
1190 Syntax:
1191
1192 .. code-block:: ada
1193
1194 pragma Contract_Cases (CONTRACT_CASE {, CONTRACT_CASE});
1195
1196 CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
1197
1198 CASE_GUARD ::= boolean_EXPRESSION | others
1199
1200 CONSEQUENCE ::= boolean_EXPRESSION
1201
1202 The ``Contract_Cases`` pragma allows defining fine-grain specifications
1203 that can complement or replace the contract given by a precondition and a
1204 postcondition. Additionally, the ``Contract_Cases`` pragma can be used
1205 by testing and formal verification tools. The compiler checks its validity and,
1206 depending on the assertion policy at the point of declaration of the pragma,
1207 it may insert a check in the executable. For code generation, the contract
1208 cases
1209
1210
1211 .. code-block:: ada
1212
1213 pragma Contract_Cases (
1214 Cond1 => Pred1,
1215 Cond2 => Pred2);
1216
1217
1218 are equivalent to
1219
1220
1221 .. code-block:: ada
1222
1223 C1 : constant Boolean := Cond1; -- evaluated at subprogram entry
1224 C2 : constant Boolean := Cond2; -- evaluated at subprogram entry
1225 pragma Precondition ((C1 and not C2) or (C2 and not C1));
1226 pragma Postcondition (if C1 then Pred1);
1227 pragma Postcondition (if C2 then Pred2);
1228
1229
1230 The precondition ensures that one and only one of the case guards is
1231 satisfied on entry to the subprogram.
1232 The postcondition ensures that for the case guard that was True on entry,
1233 the corresponding consequence is True on exit. Other consequence expressions
1234 are not evaluated.
1235
1236 A precondition ``P`` and postcondition ``Q`` can also be
1237 expressed as contract cases:
1238
1239 .. code-block:: ada
1240
1241 pragma Contract_Cases (P => Q);
1242
1243
1244 The placement and visibility rules for ``Contract_Cases`` pragmas are
1245 identical to those described for preconditions and postconditions.
1246
1247 The compiler checks that boolean expressions given in case guards and
1248 consequences are valid, where the rules for case guards are the same as
1249 the rule for an expression in ``Precondition`` and the rules for
1250 consequences are the same as the rule for an expression in
1251 ``Postcondition``. In particular, attributes ``'Old`` and
1252 ``'Result`` can only be used within consequence expressions.
1253 The case guard for the last contract case may be ``others``, to denote
1254 any case not captured by the previous cases. The
1255 following is an example of use within a package spec:
1256
1257
1258 .. code-block:: ada
1259
1260 package Math_Functions is
1261 ...
1262 function Sqrt (Arg : Float) return Float;
1263 pragma Contract_Cases (((Arg in 0.0 .. 99.0) => Sqrt'Result < 10.0,
1264 Arg >= 100.0 => Sqrt'Result >= 10.0,
1265 others => Sqrt'Result = 0.0));
1266 ...
1267 end Math_Functions;
1268
1269
1270 The meaning of contract cases is that only one case should apply at each
1271 call, as determined by the corresponding case guard evaluating to True,
1272 and that the consequence for this case should hold when the subprogram
1273 returns.
1274
1275 Pragma Convention_Identifier
1276 ============================
1277 .. index:: Conventions, synonyms
1278
1279 Syntax:
1280
1281
1282 ::
1283
1284 pragma Convention_Identifier (
1285 [Name =>] IDENTIFIER,
1286 [Convention =>] convention_IDENTIFIER);
1287
1288
1289 This pragma provides a mechanism for supplying synonyms for existing
1290 convention identifiers. The ``Name`` identifier can subsequently
1291 be used as a synonym for the given convention in other pragmas (including
1292 for example pragma ``Import`` or another ``Convention_Identifier``
1293 pragma). As an example of the use of this, suppose you had legacy code
1294 which used Fortran77 as the identifier for Fortran. Then the pragma:
1295
1296
1297 .. code-block:: ada
1298
1299 pragma Convention_Identifier (Fortran77, Fortran);
1300
1301
1302 would allow the use of the convention identifier ``Fortran77`` in
1303 subsequent code, avoiding the need to modify the sources. As another
1304 example, you could use this to parameterize convention requirements
1305 according to systems. Suppose you needed to use ``Stdcall`` on
1306 windows systems, and ``C`` on some other system, then you could
1307 define a convention identifier ``Library`` and use a single
1308 ``Convention_Identifier`` pragma to specify which convention
1309 would be used system-wide.
1310
1311 Pragma CPP_Class
1312 ================
1313 .. index:: Interfacing with C++
1314
1315 Syntax:
1316
1317
1318 ::
1319
1320 pragma CPP_Class ([Entity =>] LOCAL_NAME);
1321
1322
1323 The argument denotes an entity in the current declarative region that is
1324 declared as a record type. It indicates that the type corresponds to an
1325 externally declared C++ class type, and is to be laid out the same way
1326 that C++ would lay out the type. If the C++ class has virtual primitives
1327 then the record must be declared as a tagged record type.
1328
1329 Types for which ``CPP_Class`` is specified do not have assignment or
1330 equality operators defined (such operations can be imported or declared
1331 as subprograms as required). Initialization is allowed only by constructor
1332 functions (see pragma ``CPP_Constructor``). Such types are implicitly
1333 limited if not explicitly declared as limited or derived from a limited
1334 type, and an error is issued in that case.
1335
1336 See :ref:`Interfacing_to_C++` for related information.
1337
1338 Note: Pragma ``CPP_Class`` is currently obsolete. It is supported
1339 for backward compatibility but its functionality is available
1340 using pragma ``Import`` with ``Convention`` = ``CPP``.
1341
1342 Pragma CPP_Constructor
1343 ======================
1344 .. index:: Interfacing with C++
1345
1346
1347 Syntax:
1348
1349
1350 ::
1351
1352 pragma CPP_Constructor ([Entity =>] LOCAL_NAME
1353 [, [External_Name =>] static_string_EXPRESSION ]
1354 [, [Link_Name =>] static_string_EXPRESSION ]);
1355
1356
1357 This pragma identifies an imported function (imported in the usual way
1358 with pragma ``Import``) as corresponding to a C++ constructor. If
1359 ``External_Name`` and ``Link_Name`` are not specified then the
1360 ``Entity`` argument is a name that must have been previously mentioned
1361 in a pragma ``Import`` with ``Convention`` = ``CPP``. Such name
1362 must be of one of the following forms:
1363
1364 *
1365 **function** ``Fname`` **return** T`
1366
1367 *
1368 **function** ``Fname`` **return** T'Class
1369
1370 *
1371 **function** ``Fname`` (...) **return** T`
1372
1373 *
1374 **function** ``Fname`` (...) **return** T'Class
1375
1376 where ``T`` is a limited record type imported from C++ with pragma
1377 ``Import`` and ``Convention`` = ``CPP``.
1378
1379 The first two forms import the default constructor, used when an object
1380 of type ``T`` is created on the Ada side with no explicit constructor.
1381 The latter two forms cover all the non-default constructors of the type.
1382 See the GNAT User's Guide for details.
1383
1384 If no constructors are imported, it is impossible to create any objects
1385 on the Ada side and the type is implicitly declared abstract.
1386
1387 Pragma ``CPP_Constructor`` is intended primarily for automatic generation
1388 using an automatic binding generator tool (such as the :switch:`-fdump-ada-spec`
1389 GCC switch).
1390 See :ref:`Interfacing_to_C++` for more related information.
1391
1392 Note: The use of functions returning class-wide types for constructors is
1393 currently obsolete. They are supported for backward compatibility. The
1394 use of functions returning the type T leave the Ada sources more clear
1395 because the imported C++ constructors always return an object of type T;
1396 that is, they never return an object whose type is a descendant of type T.
1397
1398 Pragma CPP_Virtual
1399 ==================
1400 .. index:: Interfacing to C++
1401
1402
1403 This pragma is now obsolete and, other than generating a warning if warnings
1404 on obsolescent features are enabled, is completely ignored.
1405 It is retained for compatibility
1406 purposes. It used to be required to ensure compatibility with C++, but
1407 is no longer required for that purpose because GNAT generates
1408 the same object layout as the G++ compiler by default.
1409
1410 See :ref:`Interfacing_to_C++` for related information.
1411
1412 Pragma CPP_Vtable
1413 =================
1414 .. index:: Interfacing with C++
1415
1416
1417 This pragma is now obsolete and, other than generating a warning if warnings
1418 on obsolescent features are enabled, is completely ignored.
1419 It used to be required to ensure compatibility with C++, but
1420 is no longer required for that purpose because GNAT generates
1421 the same object layout as the G++ compiler by default.
1422
1423 See :ref:`Interfacing_to_C++` for related information.
1424
1425 Pragma CPU
1426 ==========
1427
1428 Syntax:
1429
1430
1431 .. code-block:: ada
1432
1433 pragma CPU (EXPRESSION);
1434
1435
1436 This pragma is standard in Ada 2012, but is available in all earlier
1437 versions of Ada as an implementation-defined pragma.
1438 See Ada 2012 Reference Manual for details.
1439
1440 Pragma Deadline_Floor
1441 =====================
1442
1443 Syntax:
1444
1445
1446 .. code-block:: ada
1447
1448 pragma Deadline_Floor (time_span_EXPRESSION);
1449
1450
1451 This pragma applies only to protected types and specifies the floor
1452 deadline inherited by a task when the task enters a protected object.
1453 It is effective only when the EDF scheduling policy is used.
1454
1455 Pragma Debug
1456 ============
1457
1458 Syntax:
1459
1460
1461 ::
1462
1463 pragma Debug ([CONDITION, ]PROCEDURE_CALL_WITHOUT_SEMICOLON);
1464
1465 PROCEDURE_CALL_WITHOUT_SEMICOLON ::=
1466 PROCEDURE_NAME
1467 | PROCEDURE_PREFIX ACTUAL_PARAMETER_PART
1468
1469
1470 The procedure call argument has the syntactic form of an expression, meeting
1471 the syntactic requirements for pragmas.
1472
1473 If debug pragmas are not enabled or if the condition is present and evaluates
1474 to False, this pragma has no effect. If debug pragmas are enabled, the
1475 semantics of the pragma is exactly equivalent to the procedure call statement
1476 corresponding to the argument with a terminating semicolon. Pragmas are
1477 permitted in sequences of declarations, so you can use pragma ``Debug`` to
1478 intersperse calls to debug procedures in the middle of declarations. Debug
1479 pragmas can be enabled either by use of the command line switch *-gnata*
1480 or by use of the pragma ``Check_Policy`` with a first argument of
1481 ``Debug``.
1482
1483 Pragma Debug_Policy
1484 ===================
1485
1486 Syntax:
1487
1488
1489 .. code-block:: ada
1490
1491 pragma Debug_Policy (CHECK | DISABLE | IGNORE | ON | OFF);
1492
1493
1494 This pragma is equivalent to a corresponding ``Check_Policy`` pragma
1495 with a first argument of ``Debug``. It is retained for historical
1496 compatibility reasons.
1497
1498 .. _Pragma-Default_Initial_Condition:
1499
1500 Pragma Default_Initial_Condition
1501 ================================
1502
1503 Syntax:
1504
1505 .. code-block:: ada
1506
1507 pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
1508
1509 For the semantics of this pragma, see the entry for aspect
1510 ``Default_Initial_Condition`` in the SPARK 2014 Reference Manual, section 7.3.3.
1511
1512 Pragma Default_Scalar_Storage_Order
1513 ===================================
1514 .. index:: Default_Scalar_Storage_Order
1515
1516 .. index:: Scalar_Storage_Order
1517
1518
1519 Syntax:
1520
1521
1522 .. code-block:: ada
1523
1524 pragma Default_Scalar_Storage_Order (High_Order_First | Low_Order_First);
1525
1526
1527 Normally if no explicit ``Scalar_Storage_Order`` is given for a record
1528 type or array type, then the scalar storage order defaults to the ordinary
1529 default for the target. But this default may be overridden using this pragma.
1530 The pragma may appear as a configuration pragma, or locally within a package
1531 spec or declarative part. In the latter case, it applies to all subsequent
1532 types declared within that package spec or declarative part.
1533
1534 The following example shows the use of this pragma:
1535
1536
1537 .. code-block:: ada
1538
1539 pragma Default_Scalar_Storage_Order (High_Order_First);
1540 with System; use System;
1541 package DSSO1 is
1542 type H1 is record
1543 a : Integer;
1544 end record;
1545
1546 type L2 is record
1547 a : Integer;
1548 end record;
1549 for L2'Scalar_Storage_Order use Low_Order_First;
1550
1551 type L2a is new L2;
1552
1553 package Inner is
1554 type H3 is record
1555 a : Integer;
1556 end record;
1557
1558 pragma Default_Scalar_Storage_Order (Low_Order_First);
1559
1560 type L4 is record
1561 a : Integer;
1562 end record;
1563 end Inner;
1564
1565 type H4a is new Inner.L4;
1566
1567 type H5 is record
1568 a : Integer;
1569 end record;
1570 end DSSO1;
1571
1572
1573 In this example record types with names starting with *L* have `Low_Order_First` scalar
1574 storage order, and record types with names starting with *H* have ``High_Order_First``.
1575 Note that in the case of ``H4a``, the order is not inherited
1576 from the parent type. Only an explicitly set ``Scalar_Storage_Order``
1577 gets inherited on type derivation.
1578
1579 If this pragma is used as a configuration pragma which appears within a
1580 configuration pragma file (as opposed to appearing explicitly at the start
1581 of a single unit), then the binder will require that all units in a partition
1582 be compiled in a similar manner, other than run-time units, which are not
1583 affected by this pragma. Note that the use of this form is discouraged because
1584 it may significantly degrade the run-time performance of the software, instead
1585 the default scalar storage order ought to be changed only on a local basis.
1586
1587 Pragma Default_Storage_Pool
1588 ===========================
1589 .. index:: Default_Storage_Pool
1590
1591
1592 Syntax:
1593
1594
1595 .. code-block:: ada
1596
1597 pragma Default_Storage_Pool (storage_pool_NAME | null);
1598
1599
1600 This pragma is standard in Ada 2012, but is available in all earlier
1601 versions of Ada as an implementation-defined pragma.
1602 See Ada 2012 Reference Manual for details.
1603
1604 .. _Pragma-Depends:
1605
1606 Pragma Depends
1607 ==============
1608
1609 Syntax:
1610
1611 .. code-block:: ada
1612
1613 pragma Depends (DEPENDENCY_RELATION);
1614
1615 DEPENDENCY_RELATION ::=
1616 null
1617 | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
1618
1619 DEPENDENCY_CLAUSE ::=
1620 OUTPUT_LIST =>[+] INPUT_LIST
1621 | NULL_DEPENDENCY_CLAUSE
1622
1623 NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
1624
1625 OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
1626
1627 INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
1628
1629 OUTPUT ::= NAME | FUNCTION_RESULT
1630 INPUT ::= NAME
1631
1632 where FUNCTION_RESULT is a function Result attribute_reference
1633
1634 For the semantics of this pragma, see the entry for aspect ``Depends`` in the
1635 SPARK 2014 Reference Manual, section 6.1.5.
1636
1637 Pragma Detect_Blocking
1638 ======================
1639
1640 Syntax:
1641
1642 .. code-block:: ada
1643
1644 pragma Detect_Blocking;
1645
1646
1647 This is a standard pragma in Ada 2005, that is available in all earlier
1648 versions of Ada as an implementation-defined pragma.
1649
1650 This is a configuration pragma that forces the detection of potentially
1651 blocking operations within a protected operation, and to raise Program_Error
1652 if that happens.
1653
1654 Pragma Disable_Atomic_Synchronization
1655 =====================================
1656
1657 .. index:: Atomic Synchronization
1658
1659 Syntax:
1660
1661 ::
1662
1663 pragma Disable_Atomic_Synchronization [(Entity)];
1664
1665 pragma Enable_Atomic_Synchronization [(Entity)];
1666
1667 Ada requires that accesses (reads or writes) of an atomic variable be
1668 regarded as synchronization points in the case of multiple tasks.
1669 Particularly in the case of multi-processors this may require special
1670 handling, e.g. the generation of memory barriers. This synchronization
1671 is performed by default, but can be turned off using pragma
1672 ``Disable_Atomic_Synchronization``.
1673 The ``Enable_Atomic_Synchronization`` pragma turns it back on.
1674
1675 The placement and scope rules for these pragmas are the same as those
1676 for ``pragma Suppress``. In particular they can be used as
1677 configuration pragmas, or in a declaration sequence where they apply
1678 until the end of the scope. If an ``Entity`` argument is present,
1679 the action applies only to that entity.
1680
1681 Pragma Dispatching_Domain
1682 =========================
1683
1684 Syntax:
1685
1686
1687 .. code-block:: ada
1688
1689 pragma Dispatching_Domain (EXPRESSION);
1690
1691
1692 This pragma is standard in Ada 2012, but is available in all earlier
1693 versions of Ada as an implementation-defined pragma.
1694 See Ada 2012 Reference Manual for details.
1695
1696 .. _Pragma-Effective_Reads:
1697
1698 Pragma Effective_Reads
1699 ======================
1700
1701 Syntax:
1702
1703 .. code-block:: ada
1704
1705 pragma Effective_Reads [ (static_boolean_EXPRESSION) ];
1706
1707 For the semantics of this pragma, see the entry for aspect ``Effective_Reads`` in
1708 the SPARK 2014 Reference Manual, section 7.1.2.
1709
1710 .. _Pragma-Effective_Writes:
1711
1712 Pragma Effective_Writes
1713 =======================
1714
1715 Syntax:
1716
1717 .. code-block:: ada
1718
1719 pragma Effective_Writes [ (static_boolean_EXPRESSION) ];
1720
1721 For the semantics of this pragma, see the entry for aspect ``Effective_Writes``
1722 in the SPARK 2014 Reference Manual, section 7.1.2.
1723
1724 Pragma Elaboration_Checks
1725 =========================
1726 .. index:: Elaboration control
1727
1728
1729 Syntax:
1730
1731
1732 .. code-block:: ada
1733
1734 pragma Elaboration_Checks (Dynamic | Static);
1735
1736
1737 This is a configuration pragma which specifies the elaboration model to be
1738 used during compilation. For more information on the elaboration models of
1739 GNAT, consult the chapter on elaboration order handling in the *GNAT User's
1740 Guide*.
1741
1742 The pragma may appear in the following contexts:
1743
1744 * Configuration pragmas file
1745
1746 * Prior to the context clauses of a compilation unit's initial declaration
1747
1748 Any other placement of the pragma will result in a warning and the effects of
1749 the offending pragma will be ignored.
1750
1751 If the pragma argument is ``Dynamic``, then the dynamic elaboration model is in
1752 effect. If the pragma argument is ``Static``, then the static elaboration model
1753 is in effect.
1754
1755 Pragma Eliminate
1756 ================
1757 .. index:: Elimination of unused subprograms
1758
1759
1760 Syntax:
1761
1762
1763 ::
1764
1765 pragma Eliminate (
1766 [ Unit_Name => ] IDENTIFIER | SELECTED_COMPONENT ,
1767 [ Entity => ] IDENTIFIER |
1768 SELECTED_COMPONENT |
1769 STRING_LITERAL
1770 [, Source_Location => SOURCE_TRACE ] );
1771
1772 SOURCE_TRACE ::= STRING_LITERAL
1773
1774
1775 This pragma indicates that the given entity is not used in the program to be
1776 compiled and built, thus allowing the compiler to
1777 eliminate the code or data associated with the named entity. Any reference to
1778 an eliminated entity causes a compile-time or link-time error.
1779
1780 The pragma has the following semantics, where ``U`` is the unit specified by
1781 the ``Unit_Name`` argument and ``E`` is the entity specified by the ``Entity``
1782 argument:
1783
1784 * ``E`` must be a subprogram that is explicitly declared either:
1785
1786 * Within ``U``, or
1787 * Within a generic package that is instantiated in ``U``, or
1788 * As an instance of generic subprogram instantiated in ``U``.
1789
1790 Otherwise the pragma is ignored.
1791
1792 * If ``E`` is overloaded within ``U`` then, in the absence of a
1793 ``Source_Location`` argument, all overloadings are eliminated.
1794 * If ``E`` is overloaded within ``U`` and only some overloadings
1795 are to be eliminated, then each overloading to be eliminated
1796 must be specified in a corresponding pragma ``Eliminate``
1797 with a ``Source_Location`` argument identifying the line where the
1798 declaration appears, as described below.
1799 * If ``E`` is declared as the result of a generic instantiation, then
1800 a ``Source_Location`` argument is needed, as described below.
1801
1802 Pragma ``Eliminate`` allows a program to be compiled in a system-independent
1803 manner, so that unused entities are eliminated but without
1804 needing to modify the source text. Normally the required set of
1805 ``Eliminate`` pragmas is constructed automatically using the ``gnatelim`` tool.
1806
1807 Any source file change that removes, splits, or
1808 adds lines may make the set of ``Eliminate`` pragmas invalid because their
1809 ``Source_Location`` argument values may get out of date.
1810
1811 Pragma ``Eliminate`` may be used where the referenced entity is a dispatching
1812 operation. In this case all the subprograms to which the given operation can
1813 dispatch are considered to be unused (are never called as a result of a direct
1814 or a dispatching call).
1815
1816 The string literal given for the source location specifies the line number
1817 of the declaration of the entity, using the following syntax for ``SOURCE_TRACE``:
1818
1819 ::
1820
1821 SOURCE_TRACE ::= SOURCE_REFERENCE [ LBRACKET SOURCE_TRACE RBRACKET ]
1822
1823 LBRACKET ::= '['
1824 RBRACKET ::= ']'
1825
1826 SOURCE_REFERENCE ::= FILE_NAME : LINE_NUMBER
1827
1828 LINE_NUMBER ::= DIGIT {DIGIT}
1829
1830
1831 Spaces around the colon in a ``SOURCE_REFERENCE`` are optional.
1832
1833 The source trace that is given as the ``Source_Location`` must obey the
1834 following rules (or else the pragma is ignored), where ``U`` is
1835 the unit ``U`` specified by the ``Unit_Name`` argument and ``E`` is the
1836 subprogram specified by the ``Entity`` argument:
1837
1838 * ``FILE_NAME`` is the short name (with no directory
1839 information) of the Ada source file for ``U``, using the required syntax
1840 for the underlying file system (e.g. case is significant if the underlying
1841 operating system is case sensitive).
1842 If ``U`` is a package and ``E`` is a subprogram declared in the package
1843 specification and its full declaration appears in the package body,
1844 then the relevant source file is the one for the package specification;
1845 analogously if ``U`` is a generic package.
1846
1847 * If ``E`` is not declared in a generic instantiation (this includes
1848 generic subprogram instances), the source trace includes only one source
1849 line reference. ``LINE_NUMBER`` gives the line number of the occurrence
1850 of the declaration of ``E`` within the source file (as a decimal literal
1851 without an exponent or point).
1852
1853 * If ``E`` is declared by a generic instantiation, its source trace
1854 (from left to right) starts with the source location of the
1855 declaration of ``E`` in the generic unit and ends with the source
1856 location of the instantiation, given in square brackets. This approach is
1857 applied recursively with nested instantiations: the rightmost (nested
1858 most deeply in square brackets) element of the source trace is the location
1859 of the outermost instantiation, and the leftmost element (that is, outside
1860 of any square brackets) is the location of the declaration of ``E`` in
1861 the generic unit.
1862
1863 Examples:
1864
1865 .. code-block:: ada
1866
1867 pragma Eliminate (Pkg0, Proc);
1868 -- Eliminate (all overloadings of) Proc in Pkg0
1869
1870 pragma Eliminate (Pkg1, Proc,
1871 Source_Location => "pkg1.ads:8");
1872 -- Eliminate overloading of Proc at line 8 in pkg1.ads
1873
1874 -- Assume the following file contents:
1875 -- gen_pkg.ads
1876 -- 1: generic
1877 -- 2: type T is private;
1878 -- 3: package Gen_Pkg is
1879 -- 4: procedure Proc(N : T);
1880 -- ... ...
1881 -- ... end Gen_Pkg;
1882 --
1883 -- q.adb
1884 -- 1: with Gen_Pkg;
1885 -- 2: procedure Q is
1886 -- 3: package Inst_Pkg is new Gen_Pkg(Integer);
1887 -- ... -- No calls on Inst_Pkg.Proc
1888 -- ... end Q;
1889
1890 -- The following pragma eliminates Inst_Pkg.Proc from Q
1891 pragma Eliminate (Q, Proc,
1892 Source_Location => "gen_pkg.ads:4[q.adb:3]");
1893
1894
1895
1896 Pragma Enable_Atomic_Synchronization
1897 ====================================
1898 .. index:: Atomic Synchronization
1899
1900
1901 Syntax:
1902
1903
1904 ::
1905
1906 pragma Enable_Atomic_Synchronization [(Entity)];
1907
1908 Reenables atomic synchronization; see ``pragma Disable_Atomic_Synchronization``
1909 for details.
1910
1911 Pragma Exceptional_Cases
1912 ========================
1913 .. index:: Exceptional_Cases
1914
1915 Syntax:
1916
1917
1918 ::
1919
1920 pragma Exceptional_Cases (EXCEPTIONAL_CASE_LIST);
1921
1922 EXCEPTIONAL_CASE_LIST ::= EXCEPTIONAL_CASE {, EXCEPTIONAL_CASE}
1923 EXCEPTIONAL_CASE ::= exception_choice {'|' exception_choice} => CONSEQUENCE
1924 CONSEQUENCE ::= Boolean_expression
1925
1926 For the semantics of this aspect, see the SPARK 2014 Reference Manual, section
1927 6.1.9.
1928
1929 Pragma Exit_Cases
1930 =================
1931 .. index:: Exit_Cases
1932
1933 Syntax:
1934
1935 ::
1936
1937 pragma Exit_Cases (EXIT_CASE_LIST);
1938
1939 EXIT_CASE_LIST ::= EXIT_CASE {, EXIT_CASE}
1940 EXIT_CASE ::= GUARD => EXIT_KIND
1941 EXIT_KIND ::= Normal_Return
1942 | Exception_Raised
1943 | (Exception_Raised => exception_name)
1944 GUARD ::= Boolean_expression
1945
1946 For the semantics of this aspect, see the SPARK 2014 Reference Manual, section
1947 6.1.10.
1948
1949 Pragma Export_Function
1950 ======================
1951 .. index:: Argument passing mechanisms
1952
1953
1954 Syntax:
1955
1956
1957 ::
1958
1959 pragma Export_Function (
1960 [Internal =>] LOCAL_NAME
1961 [, [External =>] EXTERNAL_SYMBOL]
1962 [, [Parameter_Types =>] PARAMETER_TYPES]
1963 [, [Result_Type =>] result_SUBTYPE_MARK]
1964 [, [Mechanism =>] MECHANISM]
1965 [, [Result_Mechanism =>] MECHANISM_NAME]);
1966
1967 EXTERNAL_SYMBOL ::=
1968 IDENTIFIER
1969 | static_string_EXPRESSION
1970 | ""
1971
1972 PARAMETER_TYPES ::=
1973 null
1974 | TYPE_DESIGNATOR {, TYPE_DESIGNATOR}
1975
1976 TYPE_DESIGNATOR ::=
1977 subtype_NAME
1978 | subtype_Name ' Access
1979
1980 MECHANISM ::=
1981 MECHANISM_NAME
1982 | (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION})
1983
1984 MECHANISM_ASSOCIATION ::=
1985 [formal_parameter_NAME =>] MECHANISM_NAME
1986
1987 MECHANISM_NAME ::= Value | Reference
1988
1989
1990 Use this pragma to make a function externally callable and optionally
1991 provide information on mechanisms to be used for passing parameter and
1992 result values. We recommend, for the purposes of improving portability,
1993 this pragma always be used in conjunction with a separate pragma
1994 ``Export``, which must precede the pragma ``Export_Function``.
1995 GNAT does not require a separate pragma ``Export``, but if none is
1996 present, ``Convention Ada`` is assumed, which is usually
1997 not what is wanted, so it is usually appropriate to use this
1998 pragma in conjunction with a ``Export`` or ``Convention``
1999 pragma that specifies the desired foreign convention.
2000 Pragma ``Export_Function``
2001 (and ``Export``, if present) must appear in the same declarative
2002 region as the function to which they apply.
2003
2004 The ``internal_name`` must uniquely designate the function to which the
2005 pragma applies. If more than one function name exists of this name in
2006 the declarative part you must use the ``Parameter_Types`` and
2007 ``Result_Type`` parameters to achieve the required
2008 unique designation. The `subtype_mark`\ s in these parameters must
2009 exactly match the subtypes in the corresponding function specification,
2010 using positional notation to match parameters with subtype marks.
2011 The form with an ``'Access`` attribute can be used to match an
2012 anonymous access parameter.
2013
2014 .. index:: Suppressing external name
2015
2016 Special treatment is given if the EXTERNAL is an explicit null
2017 string or a static string expressions that evaluates to the null
2018 string. In this case, no external name is generated. This form
2019 still allows the specification of parameter mechanisms.
2020
2021 Pragma Export_Object
2022 ====================
2023
2024 Syntax:
2025
2026
2027 ::
2028
2029 pragma Export_Object (
2030 [Internal =>] LOCAL_NAME
2031 [, [External =>] EXTERNAL_SYMBOL]
2032 [, [Size =>] EXTERNAL_SYMBOL]);
2033
2034 EXTERNAL_SYMBOL ::=
2035 IDENTIFIER
2036 | static_string_EXPRESSION
2037
2038
2039 This pragma designates an object as exported, and apart from the
2040 extended rules for external symbols, is identical in effect to the use of
2041 the normal ``Export`` pragma applied to an object. You may use a
2042 separate Export pragma (and you probably should from the point of view
2043 of portability), but it is not required. ``Size`` is syntax checked,
2044 but otherwise ignored by GNAT.
2045
2046 Pragma Export_Procedure
2047 =======================
2048
2049 Syntax:
2050
2051
2052 ::
2053
2054 pragma Export_Procedure (
2055 [Internal =>] LOCAL_NAME
2056 [, [External =>] EXTERNAL_SYMBOL]
2057 [, [Parameter_Types =>] PARAMETER_TYPES]
2058 [, [Mechanism =>] MECHANISM]);
2059
2060 EXTERNAL_SYMBOL ::=
2061 IDENTIFIER
2062 | static_string_EXPRESSION
2063 | ""
2064
2065 PARAMETER_TYPES ::=
2066 null
2067 | TYPE_DESIGNATOR {, TYPE_DESIGNATOR}
2068
2069 TYPE_DESIGNATOR ::=
2070 subtype_NAME
2071 | subtype_Name ' Access
2072
2073 MECHANISM ::=
2074 MECHANISM_NAME
2075 | (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION})
2076
2077 MECHANISM_ASSOCIATION ::=
2078 [formal_parameter_NAME =>] MECHANISM_NAME
2079
2080 MECHANISM_NAME ::= Value | Reference
2081
2082
2083 This pragma is identical to ``Export_Function`` except that it
2084 applies to a procedure rather than a function and the parameters
2085 ``Result_Type`` and ``Result_Mechanism`` are not permitted.
2086 GNAT does not require a separate pragma ``Export``, but if none is
2087 present, ``Convention Ada`` is assumed, which is usually
2088 not what is wanted, so it is usually appropriate to use this
2089 pragma in conjunction with a ``Export`` or ``Convention``
2090 pragma that specifies the desired foreign convention.
2091
2092 .. index:: Suppressing external name
2093
2094 Special treatment is given if the EXTERNAL is an explicit null
2095 string or a static string expressions that evaluates to the null
2096 string. In this case, no external name is generated. This form
2097 still allows the specification of parameter mechanisms.
2098
2099 Pragma Export_Valued_Procedure
2100 ==============================
2101
2102 Syntax:
2103
2104
2105 ::
2106
2107 pragma Export_Valued_Procedure (
2108 [Internal =>] LOCAL_NAME
2109 [, [External =>] EXTERNAL_SYMBOL]
2110 [, [Parameter_Types =>] PARAMETER_TYPES]
2111 [, [Mechanism =>] MECHANISM]);
2112
2113 EXTERNAL_SYMBOL ::=
2114 IDENTIFIER
2115 | static_string_EXPRESSION
2116 | ""
2117
2118 PARAMETER_TYPES ::=
2119 null
2120 | TYPE_DESIGNATOR {, TYPE_DESIGNATOR}
2121
2122 TYPE_DESIGNATOR ::=
2123 subtype_NAME
2124 | subtype_Name ' Access
2125
2126 MECHANISM ::=
2127 MECHANISM_NAME
2128 | (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION})
2129
2130 MECHANISM_ASSOCIATION ::=
2131 [formal_parameter_NAME =>] MECHANISM_NAME
2132
2133 MECHANISM_NAME ::= Value | Reference
2134
2135
2136 This pragma is identical to ``Export_Procedure`` except that the
2137 first parameter of ``LOCAL_NAME``, which must be present, must be of
2138 mode ``out``, and externally the subprogram is treated as a function
2139 with this parameter as the result of the function. GNAT provides for
2140 this capability to allow the use of ``out`` and ``in out``
2141 parameters in interfacing to external functions (which are not permitted
2142 in Ada functions).
2143 GNAT does not require a separate pragma ``Export``, but if none is
2144 present, ``Convention Ada`` is assumed, which is almost certainly
2145 not what is wanted since the whole point of this pragma is to interface
2146 with foreign language functions, so it is usually appropriate to use this
2147 pragma in conjunction with a ``Export`` or ``Convention``
2148 pragma that specifies the desired foreign convention.
2149
2150 .. index:: Suppressing external name
2151
2152 Special treatment is given if the EXTERNAL is an explicit null
2153 string or a static string expressions that evaluates to the null
2154 string. In this case, no external name is generated. This form
2155 still allows the specification of parameter mechanisms.
2156
2157 Pragma Extend_System
2158 ====================
2159 .. index:: System, extending
2160
2161 .. index:: DEC Ada 83
2162
2163
2164 Syntax:
2165
2166
2167 ::
2168
2169 pragma Extend_System ([Name =>] IDENTIFIER);
2170
2171
2172 This pragma is used to provide backwards compatibility with other
2173 implementations that extend the facilities of package ``System``. In
2174 GNAT, ``System`` contains only the definitions that are present in
2175 the Ada RM. However, other implementations, notably the DEC Ada 83
2176 implementation, provide many extensions to package ``System``.
2177
2178 For each such implementation accommodated by this pragma, GNAT provides a
2179 package :samp:`Aux_{xxx}`, e.g., ``Aux_DEC`` for the DEC Ada 83
2180 implementation, which provides the required additional definitions. You
2181 can use this package in two ways. You can ``with`` it in the normal
2182 way and access entities either by selection or using a ``use``
2183 clause. In this case no special processing is required.
2184
2185 However, if existing code contains references such as
2186 :samp:`System.{xxx}` where *xxx* is an entity in the extended
2187 definitions provided in package ``System``, you may use this pragma
2188 to extend visibility in ``System`` in a non-standard way that
2189 provides greater compatibility with the existing code. Pragma
2190 ``Extend_System`` is a configuration pragma whose single argument is
2191 the name of the package containing the extended definition
2192 (e.g., ``Aux_DEC`` for the DEC Ada case). A unit compiled under
2193 control of this pragma will be processed using special visibility
2194 processing that looks in package :samp:`System.Aux_{xxx}` where
2195 :samp:`Aux_{xxx}` is the pragma argument for any entity referenced in
2196 package ``System``, but not found in package ``System``.
2197
2198 You can use this pragma either to access a predefined ``System``
2199 extension supplied with the compiler, for example ``Aux_DEC`` or
2200 you can construct your own extension unit following the above
2201 definition. Note that such a package is a child of ``System``
2202 and thus is considered part of the implementation.
2203 To compile it you will have to use the *-gnatg* switch
2204 for compiling System units, as explained in the
2205 GNAT User's Guide.
2206
2207 .. _Pragma_Extensions_Allowed:
2208
2209 Pragma Extensions_Allowed
2210 =========================
2211 .. index:: Ada Extensions
2212
2213 .. index:: GNAT Extensions
2214
2215
2216 Syntax:
2217
2218 .. code-block:: ada
2219
2220 pragma Extensions_Allowed (On | Off | All_Extensions);
2221
2222
2223 This configuration pragma enables (via the "On" or "All_Extensions" argument)
2224 or disables (via the "Off" argument) the implementation extension mode; the
2225 pragma takes precedence over the ``-gnatX`` and ``-gnatX0`` command switches.
2226
2227 If an argument of ``"On"`` is specified, the latest version of the Ada language
2228 is implemented (currently Ada 2022) and, in addition, a curated set of GNAT
2229 specific extensions are recognized. (See the list here
2230 :ref:`here<Curated_Language_Extensions>`)
2231
2232 An argument of ``"All_Extensions"`` has the same effect except that some extra
2233 experimental extensions are enabled (See the list here
2234 :ref:`here<Experimental_Language_Extensions>`)
2235
2236 .. _Pragma-Extensions_Visible:
2237
2238 Pragma Extensions_Visible
2239 =========================
2240
2241 Syntax:
2242
2243 .. code-block:: ada
2244
2245 pragma Extensions_Visible [ (static_boolean_EXPRESSION) ];
2246
2247 For the semantics of this pragma, see the entry for aspect ``Extensions_Visible``
2248 in the SPARK 2014 Reference Manual, section 6.1.7.
2249
2250 Pragma External
2251 ===============
2252
2253 Syntax:
2254
2255
2256 ::
2257
2258 pragma External (
2259 [ Convention =>] convention_IDENTIFIER,
2260 [ Entity =>] LOCAL_NAME
2261 [, [External_Name =>] static_string_EXPRESSION ]
2262 [, [Link_Name =>] static_string_EXPRESSION ]);
2263
2264
2265 This pragma is identical in syntax and semantics to pragma
2266 ``Export`` as defined in the Ada Reference Manual. It is
2267 provided for compatibility with some Ada 83 compilers that
2268 used this pragma for exactly the same purposes as pragma
2269 ``Export`` before the latter was standardized.
2270
2271 Pragma External_Name_Casing
2272 ===========================
2273 .. index:: Dec Ada 83 casing compatibility
2274
2275 .. index:: External Names, casing
2276
2277 .. index:: Casing of External names
2278
2279
2280 Syntax:
2281
2282
2283 ::
2284
2285 pragma External_Name_Casing (
2286 Uppercase | Lowercase
2287 [, Uppercase | Lowercase | As_Is]);
2288
2289
2290 This pragma provides control over the casing of external names associated
2291 with Import and Export pragmas. There are two cases to consider:
2292
2293
2294
2295 * Implicit external names
2296
2297 Implicit external names are derived from identifiers. The most common case
2298 arises when a standard Ada Import or Export pragma is used with only two
2299 arguments, as in:
2300
2301 .. code-block:: ada
2302
2303 pragma Import (C, C_Routine);
2304
2305 Since Ada is a case-insensitive language, the spelling of the identifier in
2306 the Ada source program does not provide any information on the desired
2307 casing of the external name, and so a convention is needed. In GNAT the
2308 default treatment is that such names are converted to all lower case
2309 letters. This corresponds to the normal C style in many environments.
2310 The first argument of pragma ``External_Name_Casing`` can be used to
2311 control this treatment. If ``Uppercase`` is specified, then the name
2312 will be forced to all uppercase letters. If ``Lowercase`` is specified,
2313 then the normal default of all lower case letters will be used.
2314
2315 This same implicit treatment is also used in the case of extended DEC Ada 83
2316 compatible Import and Export pragmas where an external name is explicitly
2317 specified using an identifier rather than a string.
2318
2319
2320 * Explicit external names
2321
2322 Explicit external names are given as string literals. The most common case
2323 arises when a standard Ada Import or Export pragma is used with three
2324 arguments, as in:
2325
2326 .. code-block:: ada
2327
2328 pragma Import (C, C_Routine, "C_routine");
2329
2330 In this case, the string literal normally provides the exact casing required
2331 for the external name. The second argument of pragma
2332 ``External_Name_Casing`` may be used to modify this behavior.
2333 If ``Uppercase`` is specified, then the name
2334 will be forced to all uppercase letters. If ``Lowercase`` is specified,
2335 then the name will be forced to all lowercase letters. A specification of
2336 ``As_Is`` provides the normal default behavior in which the casing is
2337 taken from the string provided.
2338
2339 This pragma may appear anywhere that a pragma is valid. In particular, it
2340 can be used as a configuration pragma in the :file:`gnat.adc` file, in which
2341 case it applies to all subsequent compilations, or it can be used as a program
2342 unit pragma, in which case it only applies to the current unit, or it can
2343 be used more locally to control individual Import/Export pragmas.
2344
2345 It was primarily intended for use with OpenVMS systems, where many
2346 compilers convert all symbols to upper case by default. For interfacing to
2347 such compilers (e.g., the DEC C compiler), it may be convenient to use
2348 the pragma:
2349
2350 .. code-block:: ada
2351
2352 pragma External_Name_Casing (Uppercase, Uppercase);
2353
2354
2355 to enforce the upper casing of all external symbols.
2356
2357 Pragma Fast_Math
2358 ================
2359
2360 Syntax:
2361
2362
2363 .. code-block:: ada
2364
2365 pragma Fast_Math;
2366
2367
2368 This is a configuration pragma which activates a mode in which speed is
2369 considered more important for floating-point operations than absolutely
2370 accurate adherence to the requirements of the standard. Currently the
2371 following operations are affected:
2372
2373
2374
2375 *Complex Multiplication*
2376 The normal simple formula for complex multiplication can result in intermediate
2377 overflows for numbers near the end of the range. The Ada standard requires that
2378 this situation be detected and corrected by scaling, but in Fast_Math mode such
2379 cases will simply result in overflow. Note that to take advantage of this you
2380 must instantiate your own version of ``Ada.Numerics.Generic_Complex_Types``
2381 under control of the pragma, rather than use the preinstantiated versions.
2382
2383 .. _Pragma-Favor_Top_Level:
2384
2385 Pragma Favor_Top_Level
2386 ======================
2387
2388 Syntax:
2389
2390
2391 .. code-block:: ada
2392
2393 pragma Favor_Top_Level (type_LOCAL_NAME);
2394
2395
2396 The argument of pragma ``Favor_Top_Level`` must be a named access-to-subprogram
2397 type. This pragma is an efficiency hint to the compiler, regarding the use of
2398 ``'Access`` or ``'Unrestricted_Access`` on nested (non-library-level) subprograms.
2399 The pragma means that nested subprograms are not used with this type, or are
2400 rare, so that the generated code should be efficient in the top-level case.
2401 When this pragma is used, dynamically generated trampolines may be used on some
2402 targets for nested subprograms. See restriction ``No_Implicit_Dynamic_Code``.
2403
2404 Pragma Finalize_Storage_Only
2405 ============================
2406
2407 Syntax:
2408
2409
2410 .. code-block:: ada
2411
2412 pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
2413
2414
2415 The argument of pragma ``Finalize_Storage_Only`` must denote a local type which
2416 is derived from ``Ada.Finalization.Controlled`` or ``Limited_Controlled``. The
2417 pragma suppresses the call to ``Finalize`` for declared library-level objects
2418 of the argument type. This is mostly useful for types where finalization is
2419 only used to deal with storage reclamation since in most environments it is
2420 not necessary to reclaim memory just before terminating execution, hence the
2421 name. Note that this pragma does not suppress Finalize calls for library-level
2422 heap-allocated objects (see pragma ``No_Heap_Finalization``).
2423
2424 Pragma Float_Representation
2425 ===========================
2426
2427 Syntax::
2428
2429 pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
2430
2431 FLOAT_REP ::= VAX_Float | IEEE_Float
2432
2433
2434 In the one argument form, this pragma is a configuration pragma which
2435 allows control over the internal representation chosen for the predefined
2436 floating point types declared in the packages ``Standard`` and
2437 ``System``. This pragma is only provided for compatibility and has no effect.
2438
2439 The two argument form specifies the representation to be used for
2440 the specified floating-point type. The argument must
2441 be ``IEEE_Float`` to specify the use of IEEE format, as follows:
2442
2443 *
2444 For a digits value of 6, 32-bit IEEE short format will be used.
2445 *
2446 For a digits value of 15, 64-bit IEEE long format will be used.
2447 *
2448 No other value of digits is permitted.
2449
2450 .. _Pragma-Ghost:
2451
2452 Pragma Ghost
2453 ============
2454
2455 Syntax:
2456
2457 .. code-block:: ada
2458
2459 pragma Ghost [ (static_boolean_EXPRESSION) ];
2460
2461 For the semantics of this pragma, see the entry for aspect ``Ghost`` in the SPARK
2462 2014 Reference Manual, section 6.9.
2463
2464 .. _Pragma-Global:
2465
2466 Pragma Global
2467 =============
2468
2469 Syntax:
2470
2471 .. code-block:: ada
2472
2473 pragma Global (GLOBAL_SPECIFICATION);
2474
2475 GLOBAL_SPECIFICATION ::=
2476 null
2477 | (GLOBAL_LIST)
2478 | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
2479
2480 MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
2481
2482 MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
2483 GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
2484 GLOBAL_ITEM ::= NAME
2485
2486 For the semantics of this pragma, see the entry for aspect ``Global`` in the
2487 SPARK 2014 Reference Manual, section 6.1.4.
2488
2489 Pragma Ident
2490 ============
2491
2492 Syntax:
2493
2494
2495 .. code-block:: ada
2496
2497 pragma Ident (static_string_EXPRESSION);
2498
2499
2500 This pragma is identical in effect to pragma ``Comment``. It is provided
2501 for compatibility with other Ada compilers providing this pragma.
2502
2503 Pragma Ignore_Pragma
2504 ====================
2505
2506 Syntax:
2507
2508
2509 .. code-block:: ada
2510
2511 pragma Ignore_Pragma (pragma_IDENTIFIER);
2512
2513 This is a configuration pragma
2514 that takes a single argument that is a simple identifier. Any subsequent
2515 use of a pragma whose pragma identifier matches this argument will be
2516 silently ignored. Any preceding use of a pragma whose pragma identifier
2517 matches this argument will be parsed and then ignored.
2518 This may be useful when legacy code or code intended
2519 for compilation with some other compiler contains pragmas that match the
2520 name, but not the exact implementation, of a GNAT pragma. The use of this
2521 pragma allows such pragmas to be ignored, which may be useful in CodePeer
2522 mode, or during porting of legacy code.
2523
2524 Pragma Implementation_Defined
2525 =============================
2526
2527 Syntax:
2528
2529
2530 .. code-block:: ada
2531
2532 pragma Implementation_Defined (local_NAME);
2533
2534
2535 This pragma marks a previously declared entity as implementation-defined.
2536 For an overloaded entity, applies to the most recent homonym.
2537
2538
2539 .. code-block:: ada
2540
2541 pragma Implementation_Defined;
2542
2543
2544 The form with no arguments appears anywhere within a scope, most
2545 typically a package spec, and indicates that all entities that are
2546 defined within the package spec are Implementation_Defined.
2547
2548 This pragma is used within the GNAT runtime library to identify
2549 implementation-defined entities introduced in language-defined units,
2550 for the purpose of implementing the No_Implementation_Identifiers
2551 restriction.
2552
2553 Pragma Implemented
2554 ==================
2555
2556 Syntax:
2557
2558
2559 ::
2560
2561 pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
2562
2563 implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
2564
2565
2566 This is an Ada 2012 representation pragma which applies to protected, task
2567 and synchronized interface primitives. The use of pragma Implemented provides
2568 a way to impose a static requirement on the overriding operation by adhering
2569 to one of the three implementation kinds: entry, protected procedure or any of
2570 the above. This pragma is available in all earlier versions of Ada as an
2571 implementation-defined pragma.
2572
2573
2574 .. code-block:: ada
2575
2576 type Synch_Iface is synchronized interface;
2577 procedure Prim_Op (Obj : in out Iface) is abstract;
2578 pragma Implemented (Prim_Op, By_Protected_Procedure);
2579
2580 protected type Prot_1 is new Synch_Iface with
2581 procedure Prim_Op; -- Legal
2582 end Prot_1;
2583
2584 protected type Prot_2 is new Synch_Iface with
2585 entry Prim_Op; -- Illegal
2586 end Prot_2;
2587
2588 task type Task_Typ is new Synch_Iface with
2589 entry Prim_Op; -- Illegal
2590 end Task_Typ;
2591
2592
2593 When applied to the procedure_or_entry_NAME of a requeue statement, pragma
2594 Implemented determines the runtime behavior of the requeue. Implementation kind
2595 By_Entry guarantees that the action of requeueing will proceed from an entry to
2596 another entry. Implementation kind By_Protected_Procedure transforms the
2597 requeue into a dispatching call, thus eliminating the chance of blocking. Kind
2598 By_Any shares the behavior of By_Entry and By_Protected_Procedure depending on
2599 the target's overriding subprogram kind.
2600
2601 Pragma Implicit_Packing
2602 =======================
2603 .. index:: Rational Profile
2604
2605 Syntax:
2606
2607
2608 .. code-block:: ada
2609
2610 pragma Implicit_Packing;
2611
2612
2613 This is a configuration pragma that requests implicit packing for packed
2614 arrays for which a size clause is given but no explicit pragma Pack or
2615 specification of Component_Size is present. It also applies to records
2616 where no record representation clause is present. Consider this example:
2617
2618
2619 .. code-block:: ada
2620
2621 type R is array (0 .. 7) of Boolean;
2622 for R'Size use 8;
2623
2624
2625 In accordance with the recommendation in the RM (RM 13.3(53)), a Size clause
2626 does not change the layout of a composite object. So the Size clause in the
2627 above example is normally rejected, since the default layout of the array uses
2628 8-bit components, and thus the array requires a minimum of 64 bits.
2629
2630 If this declaration is compiled in a region of code covered by an occurrence
2631 of the configuration pragma Implicit_Packing, then the Size clause in this
2632 and similar examples will cause implicit packing and thus be accepted. For
2633 this implicit packing to occur, the type in question must be an array of small
2634 components whose size is known at compile time, and the Size clause must
2635 specify the exact size that corresponds to the number of elements in the array
2636 multiplied by the size in bits of the component type (both single and
2637 multi-dimensioned arrays can be controlled with this pragma).
2638
2639 .. index:: Array packing
2640
2641 Similarly, the following example shows the use in the record case
2642
2643
2644 .. code-block:: ada
2645
2646 type r is record
2647 a, b, c, d, e, f, g, h : boolean;
2648 chr : character;
2649 end record;
2650 for r'size use 16;
2651
2652
2653 Without a pragma Pack, each Boolean field requires 8 bits, so the
2654 minimum size is 72 bits, but with a pragma Pack, 16 bits would be
2655 sufficient. The use of pragma Implicit_Packing allows this record
2656 declaration to compile without an explicit pragma Pack.
2657
2658 Pragma Import_Function
2659 ======================
2660
2661 Syntax:
2662
2663
2664 ::
2665
2666 pragma Import_Function (
2667 [Internal =>] LOCAL_NAME,
2668 [, [External =>] EXTERNAL_SYMBOL]
2669 [, [Parameter_Types =>] PARAMETER_TYPES]
2670 [, [Result_Type =>] SUBTYPE_MARK]
2671 [, [Mechanism =>] MECHANISM]
2672 [, [Result_Mechanism =>] MECHANISM_NAME]);
2673
2674 EXTERNAL_SYMBOL ::=
2675 IDENTIFIER
2676 | static_string_EXPRESSION
2677
2678 PARAMETER_TYPES ::=
2679 null
2680 | TYPE_DESIGNATOR {, TYPE_DESIGNATOR}
2681
2682 TYPE_DESIGNATOR ::=
2683 subtype_NAME
2684 | subtype_Name ' Access
2685
2686 MECHANISM ::=
2687 MECHANISM_NAME
2688 | (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION})
2689
2690 MECHANISM_ASSOCIATION ::=
2691 [formal_parameter_NAME =>] MECHANISM_NAME
2692
2693 MECHANISM_NAME ::=
2694 Value
2695 | Reference
2696
2697
2698 This pragma is used in conjunction with a pragma ``Import`` to
2699 specify additional information for an imported function. The pragma
2700 ``Import`` (or equivalent pragma ``Interface``) must precede the
2701 ``Import_Function`` pragma and both must appear in the same
2702 declarative part as the function specification.
2703
2704 The ``Internal`` argument must uniquely designate
2705 the function to which the
2706 pragma applies. If more than one function name exists of this name in
2707 the declarative part you must use the ``Parameter_Types`` and
2708 ``Result_Type`` parameters to achieve the required unique
2709 designation. Subtype marks in these parameters must exactly match the
2710 subtypes in the corresponding function specification, using positional
2711 notation to match parameters with subtype marks.
2712 The form with an ``'Access`` attribute can be used to match an
2713 anonymous access parameter.
2714
2715 You may optionally use the ``Mechanism`` and ``Result_Mechanism``
2716 parameters to specify passing mechanisms for the
2717 parameters and result. If you specify a single mechanism name, it
2718 applies to all parameters. Otherwise you may specify a mechanism on a
2719 parameter by parameter basis using either positional or named
2720 notation. If the mechanism is not specified, the default mechanism
2721 is used.
2722
2723 Pragma Import_Object
2724 ====================
2725
2726 Syntax:
2727
2728
2729 ::
2730
2731 pragma Import_Object (
2732 [Internal =>] LOCAL_NAME
2733 [, [External =>] EXTERNAL_SYMBOL]
2734 [, [Size =>] EXTERNAL_SYMBOL]);
2735
2736 EXTERNAL_SYMBOL ::=
2737 IDENTIFIER
2738 | static_string_EXPRESSION
2739
2740
2741 This pragma designates an object as imported, and apart from the
2742 extended rules for external symbols, is identical in effect to the use of
2743 the normal ``Import`` pragma applied to an object. Unlike the
2744 subprogram case, you need not use a separate ``Import`` pragma,
2745 although you may do so (and probably should do so from a portability
2746 point of view). ``size`` is syntax checked, but otherwise ignored by
2747 GNAT.
2748
2749 Pragma Import_Procedure
2750 =======================
2751
2752 Syntax:
2753
2754
2755 ::
2756
2757 pragma Import_Procedure (
2758 [Internal =>] LOCAL_NAME
2759 [, [External =>] EXTERNAL_SYMBOL]
2760 [, [Parameter_Types =>] PARAMETER_TYPES]
2761 [, [Mechanism =>] MECHANISM]);
2762
2763 EXTERNAL_SYMBOL ::=
2764 IDENTIFIER
2765 | static_string_EXPRESSION
2766
2767 PARAMETER_TYPES ::=
2768 null
2769 | TYPE_DESIGNATOR {, TYPE_DESIGNATOR}
2770
2771 TYPE_DESIGNATOR ::=
2772 subtype_NAME
2773 | subtype_Name ' Access
2774
2775 MECHANISM ::=
2776 MECHANISM_NAME
2777 | (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION})
2778
2779 MECHANISM_ASSOCIATION ::=
2780 [formal_parameter_NAME =>] MECHANISM_NAME
2781
2782 MECHANISM_NAME ::= Value | Reference
2783
2784
2785 This pragma is identical to ``Import_Function`` except that it
2786 applies to a procedure rather than a function and the parameters
2787 ``Result_Type`` and ``Result_Mechanism`` are not permitted.
2788
2789 Pragma Import_Valued_Procedure
2790 ==============================
2791
2792 Syntax:
2793
2794
2795 ::
2796
2797 pragma Import_Valued_Procedure (
2798 [Internal =>] LOCAL_NAME
2799 [, [External =>] EXTERNAL_SYMBOL]
2800 [, [Parameter_Types =>] PARAMETER_TYPES]
2801 [, [Mechanism =>] MECHANISM]);
2802
2803 EXTERNAL_SYMBOL ::=
2804 IDENTIFIER
2805 | static_string_EXPRESSION
2806
2807 PARAMETER_TYPES ::=
2808 null
2809 | TYPE_DESIGNATOR {, TYPE_DESIGNATOR}
2810
2811 TYPE_DESIGNATOR ::=
2812 subtype_NAME
2813 | subtype_Name ' Access
2814
2815 MECHANISM ::=
2816 MECHANISM_NAME
2817 | (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION})
2818
2819 MECHANISM_ASSOCIATION ::=
2820 [formal_parameter_NAME =>] MECHANISM_NAME
2821
2822 MECHANISM_NAME ::= Value | Reference
2823
2824
2825 This pragma is identical to ``Import_Procedure`` except that the
2826 first parameter of ``LOCAL_NAME``, which must be present, must be of
2827 mode ``out``, and externally the subprogram is treated as a function
2828 with this parameter as the result of the function. The purpose of this
2829 capability is to allow the use of ``out`` and ``in out``
2830 parameters in interfacing to external functions (which are not permitted
2831 in Ada functions). You may optionally use the ``Mechanism``
2832 parameters to specify passing mechanisms for the parameters.
2833 If you specify a single mechanism name, it applies to all parameters.
2834 Otherwise you may specify a mechanism on a parameter by parameter
2835 basis using either positional or named notation. If the mechanism is not
2836 specified, the default mechanism is used.
2837
2838 Note that it is important to use this pragma in conjunction with a separate
2839 pragma Import that specifies the desired convention, since otherwise the
2840 default convention is Ada, which is almost certainly not what is required.
2841
2842 Pragma Independent
2843 ==================
2844
2845 Syntax:
2846
2847
2848 .. code-block:: ada
2849
2850 pragma Independent (component_LOCAL_NAME);
2851
2852
2853 This pragma is standard in Ada 2012 mode (which also provides an aspect
2854 of the same name). It is also available as an implementation-defined
2855 pragma in all earlier versions. It specifies that the
2856 designated object or all objects of the designated type must be
2857 independently addressable. This means that separate tasks can safely
2858 manipulate such objects. For example, if two components of a record are
2859 independent, then two separate tasks may access these two components.
2860 This may place
2861 constraints on the representation of the object (for instance prohibiting
2862 tight packing).
2863
2864 Pragma Independent_Components
2865 =============================
2866
2867 Syntax:
2868
2869
2870 .. code-block:: ada
2871
2872 pragma Independent_Components (Local_NAME);
2873
2874
2875 This pragma is standard in Ada 2012 mode (which also provides an aspect
2876 of the same name). It is also available as an implementation-defined
2877 pragma in all earlier versions. It specifies that the components of the
2878 designated object, or the components of each object of the designated
2879 type, must be
2880 independently addressable. This means that separate tasks can safely
2881 manipulate separate components in the composite object. This may place
2882 constraints on the representation of the object (for instance prohibiting
2883 tight packing).
2884
2885 .. _Pragma-Initial_Condition:
2886
2887 Pragma Initial_Condition
2888 ========================
2889
2890 Syntax:
2891
2892 .. code-block:: ada
2893
2894 pragma Initial_Condition (boolean_EXPRESSION);
2895
2896 For the semantics of this pragma, see the entry for aspect ``Initial_Condition``
2897 in the SPARK 2014 Reference Manual, section 7.1.6.
2898
2899 Pragma Initialize_Scalars
2900 =========================
2901 .. index:: debugging with Initialize_Scalars
2902
2903 Syntax:
2904
2905
2906 .. code-block:: ada
2907
2908 pragma Initialize_Scalars
2909 [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
2910
2911 TYPE_VALUE_PAIR ::=
2912 SCALAR_TYPE => static_EXPRESSION
2913
2914 SCALAR_TYPE :=
2915 Short_Float
2916 | Float
2917 | Long_Float
2918 | Long_Long_Flat
2919 | Signed_8
2920 | Signed_16
2921 | Signed_32
2922 | Signed_64
2923 | Unsigned_8
2924 | Unsigned_16
2925 | Unsigned_32
2926 | Unsigned_64
2927
2928
2929 This pragma is similar to ``Normalize_Scalars`` conceptually but has two
2930 important differences.
2931
2932 First, there is no requirement for the pragma to be used uniformly in all units
2933 of a partition. In particular, it is fine to use this just for some or all of
2934 the application units of a partition, without needing to recompile the run-time
2935 library. In the case where some units are compiled with the pragma, and some
2936 without, then a declaration of a variable where the type is defined in package
2937 Standard or is locally declared will always be subject to initialization, as
2938 will any declaration of a scalar variable. For composite variables, whether the
2939 variable is initialized may also depend on whether the package in which the
2940 type of the variable is declared is compiled with the pragma.
2941
2942 The other important difference is that the programmer can control the value
2943 used for initializing scalar objects. This effect can be achieved in several
2944 different ways:
2945
2946 * At compile time, the programmer can specify the invalid value for a
2947 particular family of scalar types using the optional arguments of the pragma.
2948
2949 The compile-time approach is intended to optimize the generated code for the
2950 pragma, by possibly using fast operations such as ``memset``. Note that such
2951 optimizations require using values where the bytes all have the same binary
2952 representation.
2953
2954 * At bind time, the programmer has several options:
2955
2956 * Initialization with invalid values (similar to Normalize_Scalars, though
2957 for Initialize_Scalars it is not always possible to determine the invalid
2958 values in complex cases like signed component fields with nonstandard
2959 sizes).
2960
2961 * Initialization with high values.
2962
2963 * Initialization with low values.
2964
2965 * Initialization with a specific bit pattern.
2966
2967 See the GNAT User's Guide for binder options for specifying these cases.
2968
2969 The bind-time approach is intended to provide fast turnaround for testing
2970 with different values, without having to recompile the program.
2971
2972 * At execution time, the programmer can specify the invalid values using an
2973 environment variable. See the GNAT User's Guide for details.
2974
2975 The execution-time approach is intended to provide fast turnaround for
2976 testing with different values, without having to recompile and rebind the
2977 program.
2978
2979 Note that pragma ``Initialize_Scalars`` is particularly useful in conjunction
2980 with the enhanced validity checking that is now provided in GNAT, which checks
2981 for invalid values under more conditions. Using this feature (see description
2982 of the *-gnatV* flag in the GNAT User's Guide) in conjunction with pragma
2983 ``Initialize_Scalars`` provides a powerful new tool to assist in the detection
2984 of problems caused by uninitialized variables.
2985
2986 Note: the use of ``Initialize_Scalars`` has a fairly extensive effect on the
2987 generated code. This may cause your code to be substantially larger. It may
2988 also cause an increase in the amount of stack required, so it is probably a
2989 good idea to turn on stack checking (see description of stack checking in the
2990 GNAT User's Guide) when using this pragma.
2991
2992 .. _Pragma-Initializes:
2993
2994 Pragma Initializes
2995 ==================
2996
2997 Syntax:
2998
2999 .. code-block:: ada
3000
3001 pragma Initializes (INITIALIZATION_LIST);
3002
3003 INITIALIZATION_LIST ::=
3004 null
3005 | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
3006
3007 INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
3008
3009 INPUT_LIST ::=
3010 null
3011 | INPUT
3012 | (INPUT {, INPUT})
3013
3014 INPUT ::= name
3015
3016 For the semantics of this pragma, see the entry for aspect ``Initializes`` in the
3017 SPARK 2014 Reference Manual, section 7.1.5.
3018
3019 .. _Pragma-Inline_Always:
3020
3021 Pragma Inline_Always
3022 ====================
3023
3024 Syntax:
3025
3026
3027 ::
3028
3029 pragma Inline_Always (NAME [, NAME]);
3030
3031
3032 Similar to pragma ``Inline`` except that inlining is unconditional.
3033 Inline_Always instructs the compiler to inline every direct call to the
3034 subprogram or else to emit a compilation error, independently of any
3035 option, in particular *-gnatn* or *-gnatN* or the optimization level.
3036 It is an error to take the address or access of ``NAME``. It is also an error to
3037 apply this pragma to a primitive operation of a tagged type. Thanks to such
3038 restrictions, the compiler is allowed to remove the out-of-line body of ``NAME``.
3039
3040 Pragma Inline_Generic
3041 =====================
3042
3043 Syntax:
3044
3045
3046 ::
3047
3048 pragma Inline_Generic (GNAME {, GNAME});
3049
3050 GNAME ::= generic_unit_NAME | generic_instance_NAME
3051
3052
3053 This pragma is provided for compatibility with Dec Ada 83. It has
3054 no effect in GNAT (which always inlines generics), other
3055 than to check that the given names are all names of generic units or
3056 generic instances.
3057
3058 Pragma Interface
3059 ================
3060
3061 Syntax:
3062
3063
3064 ::
3065
3066 pragma Interface (
3067 [Convention =>] convention_identifier,
3068 [Entity =>] local_NAME
3069 [, [External_Name =>] static_string_expression]
3070 [, [Link_Name =>] static_string_expression]);
3071
3072
3073 This pragma is identical in syntax and semantics to
3074 the standard Ada pragma ``Import``. It is provided for compatibility
3075 with Ada 83. The definition is upwards compatible both with pragma
3076 ``Interface`` as defined in the Ada 83 Reference Manual, and also
3077 with some extended implementations of this pragma in certain Ada 83
3078 implementations. The only difference between pragma ``Interface``
3079 and pragma ``Import`` is that there is special circuitry to allow
3080 both pragmas to appear for the same subprogram entity (normally it
3081 is illegal to have multiple ``Import`` pragmas). This is useful in
3082 maintaining Ada 83/Ada 95 compatibility and is compatible with other
3083 Ada 83 compilers.
3084
3085 Pragma Interface_Name
3086 =====================
3087
3088 Syntax:
3089
3090
3091 ::
3092
3093 pragma Interface_Name (
3094 [Entity =>] LOCAL_NAME
3095 [, [External_Name =>] static_string_EXPRESSION]
3096 [, [Link_Name =>] static_string_EXPRESSION]);
3097
3098
3099 This pragma provides an alternative way of specifying the interface name
3100 for an interfaced subprogram, and is provided for compatibility with Ada
3101 83 compilers that use the pragma for this purpose. You must provide at
3102 least one of ``External_Name`` or ``Link_Name``.
3103
3104 Pragma Interrupt_Handler
3105 ========================
3106
3107 Syntax:
3108
3109
3110 .. code-block:: ada
3111
3112 pragma Interrupt_Handler (procedure_LOCAL_NAME);
3113
3114
3115 This program unit pragma is supported for parameterless protected procedures
3116 as described in Annex C of the Ada Reference Manual.
3117
3118 Pragma Interrupt_State
3119 ======================
3120
3121 Syntax:
3122
3123
3124 ::
3125
3126 pragma Interrupt_State
3127 ([Name =>] value,
3128 [State =>] SYSTEM | RUNTIME | USER);
3129
3130
3131 Normally certain interrupts are reserved to the implementation. Any attempt
3132 to attach an interrupt causes Program_Error to be raised, as described in
3133 RM C.3.2(22). A typical example is the ``SIGINT`` interrupt used in
3134 many systems for an :kbd:`Ctrl-C` interrupt. Normally this interrupt is
3135 reserved to the implementation, so that :kbd:`Ctrl-C` can be used to
3136 interrupt execution. Additionally, signals such as ``SIGSEGV``,
3137 ``SIGABRT``, ``SIGFPE`` and ``SIGILL`` are often mapped to specific
3138 Ada exceptions, or used to implement run-time functions such as the
3139 ``abort`` statement and stack overflow checking.
3140
3141 Pragma ``Interrupt_State`` provides a general mechanism for overriding
3142 such uses of interrupts. It subsumes the functionality of pragma
3143 ``Unreserve_All_Interrupts``. Pragma ``Interrupt_State`` is not
3144 available on Windows. On all other platforms than VxWorks,
3145 it applies to signals; on VxWorks, it applies to vectored hardware interrupts
3146 and may be used to mark interrupts required by the board support package
3147 as reserved.
3148
3149 Interrupts can be in one of three states:
3150
3151 * System
3152
3153 The interrupt is reserved (no Ada handler can be installed), and the
3154 Ada run-time may not install a handler. As a result you are guaranteed
3155 standard system default action if this interrupt is raised. This also allows
3156 installing a low level handler via C APIs such as sigaction(), outside
3157 of Ada control.
3158
3159 * Runtime
3160
3161 The interrupt is reserved (no Ada handler can be installed). The run time
3162 is allowed to install a handler for internal control purposes, but is
3163 not required to do so.
3164
3165 * User
3166
3167 The interrupt is unreserved. The user may install an Ada handler via
3168 Ada.Interrupts and pragma Interrupt_Handler or Attach_Handler to provide
3169 some other action.
3170
3171 These states are the allowed values of the ``State`` parameter of the
3172 pragma. The ``Name`` parameter is a value of the type
3173 ``Ada.Interrupts.Interrupt_ID``. Typically, it is a name declared in
3174 ``Ada.Interrupts.Names``.
3175
3176 This is a configuration pragma, and the binder will check that there
3177 are no inconsistencies between different units in a partition in how a
3178 given interrupt is specified. It may appear anywhere a pragma is legal.
3179
3180 The effect is to move the interrupt to the specified state.
3181
3182 By declaring interrupts to be SYSTEM, you guarantee the standard system
3183 action, such as a core dump.
3184
3185 By declaring interrupts to be USER, you guarantee that you can install
3186 a handler.
3187
3188 Note that certain signals on many operating systems cannot be caught and
3189 handled by applications. In such cases, the pragma is ignored. See the
3190 operating system documentation, or the value of the array ``Reserved``
3191 declared in the spec of package ``System.OS_Interface``.
3192
3193 Overriding the default state of signals used by the Ada runtime may interfere
3194 with an application's runtime behavior in the cases of the synchronous signals,
3195 and in the case of the signal used to implement the ``abort`` statement.
3196
3197 Pragma Interrupts_System_By_Default
3198 ===================================
3199
3200 Syntax:
3201
3202
3203 ::
3204
3205 pragma Interrupts_System_By_Default;
3206
3207 Default all interrupts to the System state as defined above in pragma
3208 ``Interrupt_State``. This is a configuration pragma.
3209
3210 .. _Pragma-Invariant:
3211
3212 Pragma Invariant
3213 ================
3214
3215 Syntax:
3216
3217
3218 ::
3219
3220 pragma Invariant
3221 ([Entity =>] private_type_LOCAL_NAME,
3222 [Check =>] EXPRESSION
3223 [,[Message =>] String_Expression]);
3224
3225
3226 This pragma provides exactly the same capabilities as the Type_Invariant aspect
3227 defined in AI05-0146-1, and in the Ada 2012 Reference Manual. The
3228 Type_Invariant aspect is fully implemented in Ada 2012 mode, but since it
3229 requires the use of the aspect syntax, which is not available except in 2012
3230 mode, it is not possible to use the Type_Invariant aspect in earlier versions
3231 of Ada. However the Invariant pragma may be used in any version of Ada. Also
3232 note that the aspect Invariant is a synonym in GNAT for the aspect
3233 Type_Invariant, but there is no pragma Type_Invariant.
3234
3235 The pragma must appear within the visible part of the package specification,
3236 after the type to which its Entity argument appears. As with the Invariant
3237 aspect, the Check expression is not analyzed until the end of the visible
3238 part of the package, so it may contain forward references. The Message
3239 argument, if present, provides the exception message used if the invariant
3240 is violated. If no Message parameter is provided, a default message that
3241 identifies the line on which the pragma appears is used.
3242
3243 It is permissible to have multiple Invariants for the same type entity, in
3244 which case they are and'ed together. It is permissible to use this pragma
3245 in Ada 2012 mode, but you cannot have both an invariant aspect and an
3246 invariant pragma for the same entity.
3247
3248 For further details on the use of this pragma, see the Ada 2012 documentation
3249 of the Type_Invariant aspect.
3250
3251 Pragma Keep_Names
3252 =================
3253
3254 Syntax:
3255
3256
3257 ::
3258
3259 pragma Keep_Names ([On =>] enumeration_first_subtype_LOCAL_NAME);
3260
3261
3262 The ``LOCAL_NAME`` argument
3263 must refer to an enumeration first subtype
3264 in the current declarative part. The effect is to retain the enumeration
3265 literal names for use by ``Image`` and ``Value`` even if a global
3266 ``Discard_Names`` pragma applies. This is useful when you want to
3267 generally suppress enumeration literal names and for example you therefore
3268 use a ``Discard_Names`` pragma in the :file:`gnat.adc` file, but you
3269 want to retain the names for specific enumeration types.
3270
3271 Pragma License
3272 ==============
3273 .. index:: License checking
3274
3275 Syntax:
3276
3277
3278 .. code-block:: ada
3279
3280 pragma License (Unrestricted | GPL | Modified_GPL | Restricted);
3281
3282
3283 This pragma is provided to allow automated checking for appropriate license
3284 conditions with respect to the standard and modified GPL. A pragma
3285 ``License``, which is a configuration pragma that typically appears at
3286 the start of a source file or in a separate :file:`gnat.adc` file, specifies
3287 the licensing conditions of a unit as follows:
3288
3289 * Unrestricted
3290 This is used for a unit that can be freely used with no license restrictions.
3291 Examples of such units are public domain units, and units from the Ada
3292 Reference Manual.
3293
3294 * GPL
3295 This is used for a unit that is licensed under the unmodified GPL, and which
3296 therefore cannot be ``with``\ ed by a restricted unit.
3297
3298 * Modified_GPL
3299 This is used for a unit licensed under the GNAT modified GPL that includes
3300 a special exception paragraph that specifically permits the inclusion of
3301 the unit in programs without requiring the entire program to be released
3302 under the GPL.
3303
3304 * Restricted
3305 This is used for a unit that is restricted in that it is not permitted to
3306 depend on units that are licensed under the GPL. Typical examples are
3307 proprietary code that is to be released under more restrictive license
3308 conditions. Note that restricted units are permitted to ``with`` units
3309 which are licensed under the modified GPL (this is the whole point of the
3310 modified GPL).
3311
3312
3313 Normally a unit with no ``License`` pragma is considered to have an
3314 unknown license, and no checking is done. However, standard GNAT headers
3315 are recognized, and license information is derived from them as follows.
3316
3317 A GNAT license header starts with a line containing 78 hyphens. The following
3318 comment text is searched for the appearance of any of the following strings.
3319
3320 If the string 'GNU General Public License' is found, then the unit is assumed
3321 to have GPL license, unless the string 'As a special exception' follows, in
3322 which case the license is assumed to be modified GPL.
3323
3324 If one of the strings
3325 'This specification is adapted from the Ada Semantic Interface' or
3326 'This specification is derived from the Ada Reference Manual' is found
3327 then the unit is assumed to be unrestricted.
3328
3329 These default actions means that a program with a restricted license pragma
3330 will automatically get warnings if a GPL unit is inappropriately
3331 ``with``\ ed. For example, the program:
3332
3333 .. code-block:: ada
3334
3335 with Sem_Ch3;
3336 with GNAT.Sockets;
3337 procedure Secret_Stuff is
3338 ...
3339 end Secret_Stuff
3340
3341
3342 if compiled with pragma ``License`` (``Restricted``) in a
3343 :file:`gnat.adc` file will generate the warning::
3344
3345 1. with Sem_Ch3;
3346 |
3347 >>> license of withed unit "Sem_Ch3" is incompatible
3348
3349 2. with GNAT.Sockets;
3350 3. procedure Secret_Stuff is
3351
3352
3353 Here we get a warning on ``Sem_Ch3`` since it is part of the GNAT
3354 compiler and is licensed under the
3355 GPL, but no warning for ``GNAT.Sockets`` which is part of the GNAT
3356 run time, and is therefore licensed under the modified GPL.
3357
3358 Pragma Link_With
3359 ================
3360
3361 Syntax:
3362
3363
3364 ::
3365
3366 pragma Link_With (static_string_EXPRESSION {,static_string_EXPRESSION});
3367
3368
3369 This pragma is provided for compatibility with certain Ada 83 compilers.
3370 It has exactly the same effect as pragma ``Linker_Options`` except
3371 that spaces occurring within one of the string expressions are treated
3372 as separators. For example, in the following case:
3373
3374 .. code-block:: ada
3375
3376 pragma Link_With ("-labc -ldef");
3377
3378
3379 results in passing the strings ``-labc`` and ``-ldef`` as two
3380 separate arguments to the linker. In addition pragma Link_With allows
3381 multiple arguments, with the same effect as successive pragmas.
3382
3383 Pragma Linker_Alias
3384 ===================
3385
3386 Syntax:
3387
3388
3389 ::
3390
3391 pragma Linker_Alias (
3392 [Entity =>] LOCAL_NAME,
3393 [Target =>] static_string_EXPRESSION);
3394
3395
3396 ``LOCAL_NAME`` must refer to an object that is declared at the library
3397 level. This pragma establishes the given entity as a linker alias for the
3398 given target. It is equivalent to ``__attribute__((alias))`` in GNU C
3399 and causes ``LOCAL_NAME`` to be emitted as an alias for the symbol
3400 ``static_string_EXPRESSION`` in the object file, that is to say no space
3401 is reserved for ``LOCAL_NAME`` by the assembler and it will be resolved
3402 to the same address as ``static_string_EXPRESSION`` by the linker.
3403
3404 The actual linker name for the target must be used (e.g., the fully
3405 encoded name with qualification in Ada, or the mangled name in C++),
3406 or it must be declared using the C convention with ``pragma Import``
3407 or ``pragma Export``.
3408
3409 Not all target machines support this pragma. On some of them it is accepted
3410 only if ``pragma Weak_External`` has been applied to ``LOCAL_NAME``.
3411
3412
3413 .. code-block:: ada
3414
3415 -- Example of the use of pragma Linker_Alias
3416
3417 package p is
3418 i : Integer := 1;
3419 pragma Export (C, i);
3420
3421 new_name_for_i : Integer;
3422 pragma Linker_Alias (new_name_for_i, "i");
3423 end p;
3424
3425
3426 Pragma Linker_Constructor
3427 =========================
3428
3429 Syntax:
3430
3431
3432 .. code-block:: ada
3433
3434 pragma Linker_Constructor (procedure_LOCAL_NAME);
3435
3436
3437 ``procedure_LOCAL_NAME`` must refer to a parameterless procedure that
3438 is declared at the library level. A procedure to which this pragma is
3439 applied will be treated as an initialization routine by the linker.
3440 It is equivalent to ``__attribute__((constructor))`` in GNU C and
3441 causes ``procedure_LOCAL_NAME`` to be invoked before the entry point
3442 of the executable is called (or immediately after the shared library is
3443 loaded if the procedure is linked in a shared library), in particular
3444 before the Ada run-time environment is set up.
3445
3446 Because of these specific contexts, the set of operations such a procedure
3447 can perform is very limited and the type of objects it can manipulate is
3448 essentially restricted to the elementary types. In particular, it must only
3449 contain code to which pragma Restrictions (No_Elaboration_Code) applies.
3450
3451 This pragma is used by GNAT to implement auto-initialization of shared Stand
3452 Alone Libraries, which provides a related capability without the restrictions
3453 listed above. Where possible, the use of Stand Alone Libraries is preferable
3454 to the use of this pragma.
3455
3456 Pragma Linker_Destructor
3457 ========================
3458
3459 Syntax:
3460
3461
3462 .. code-block:: ada
3463
3464 pragma Linker_Destructor (procedure_LOCAL_NAME);
3465
3466
3467 ``procedure_LOCAL_NAME`` must refer to a parameterless procedure that
3468 is declared at the library level. A procedure to which this pragma is
3469 applied will be treated as a finalization routine by the linker.
3470 It is equivalent to ``__attribute__((destructor))`` in GNU C and
3471 causes ``procedure_LOCAL_NAME`` to be invoked after the entry point
3472 of the executable has exited (or immediately before the shared library
3473 is unloaded if the procedure is linked in a shared library), in particular
3474 after the Ada run-time environment is shut down.
3475
3476 See ``pragma Linker_Constructor`` for the set of restrictions that apply
3477 because of these specific contexts.
3478
3479 .. _Pragma-Linker_Section:
3480
3481 Pragma Linker_Section
3482 =====================
3483
3484 Syntax:
3485
3486
3487 ::
3488
3489 pragma Linker_Section (
3490 [Entity =>] LOCAL_NAME,
3491 [Section =>] static_string_EXPRESSION);
3492
3493
3494 ``LOCAL_NAME`` must refer to an object, type, or subprogram that is
3495 declared at the library level. This pragma specifies the name of the
3496 linker section for the given entity. It is equivalent to
3497 ``__attribute__((section))`` in GNU C and causes ``LOCAL_NAME`` to
3498 be placed in the ``static_string_EXPRESSION`` section of the
3499 executable (assuming the linker doesn't rename the section).
3500 GNAT also provides an implementation defined aspect of the same name.
3501
3502 In the case of specifying this aspect for a type, the effect is to
3503 specify the corresponding section for all library-level objects of
3504 the type that do not have an explicit linker section set. Note that
3505 this only applies to whole objects, not to components of composite objects.
3506
3507 In the case of a subprogram, the linker section applies to all previously
3508 declared matching overloaded subprograms in the current declarative part
3509 which do not already have a linker section assigned. The linker section
3510 aspect is useful in this case for specifying different linker sections
3511 for different elements of such an overloaded set.
3512
3513 Note that an empty string specifies that no linker section is specified.
3514 This is not quite the same as omitting the pragma or aspect, since it
3515 can be used to specify that one element of an overloaded set of subprograms
3516 has the default linker section, or that one object of a type for which a
3517 linker section is specified should has the default linker section.
3518
3519 The compiler normally places library-level entities in standard sections
3520 depending on the class: procedures and functions generally go in the
3521 ``.text`` section, initialized variables in the ``.data`` section
3522 and uninitialized variables in the ``.bss`` section.
3523
3524 Other, special sections may exist on given target machines to map special
3525 hardware, for example I/O ports or flash memory. This pragma is a means to
3526 defer the final layout of the executable to the linker, thus fully working
3527 at the symbolic level with the compiler.
3528
3529 Some file formats do not support arbitrary sections so not all target
3530 machines support this pragma. The use of this pragma may cause a program
3531 execution to be erroneous if it is used to place an entity into an
3532 inappropriate section (e.g., a modified variable into the ``.text``
3533 section). See also ``pragma Persistent_BSS``.
3534
3535
3536 .. code-block:: ada
3537
3538 -- Example of the use of pragma Linker_Section
3539
3540 package IO_Card is
3541 Port_A : Integer;
3542 pragma Volatile (Port_A);
3543 pragma Linker_Section (Port_A, ".bss.port_a");
3544
3545 Port_B : Integer;
3546 pragma Volatile (Port_B);
3547 pragma Linker_Section (Port_B, ".bss.port_b");
3548
3549 type Port_Type is new Integer with Linker_Section => ".bss";
3550 PA : Port_Type with Linker_Section => ".bss.PA";
3551 PB : Port_Type; -- ends up in linker section ".bss"
3552
3553 procedure Q with Linker_Section => "Qsection";
3554 end IO_Card;
3555
3556 .. _Pragma-Lock_Free:
3557
3558 Pragma Lock_Free
3559 ================
3560
3561 Syntax:
3562
3563 .. code-block:: ada
3564
3565 pragma Lock_Free [ (static_boolean_EXPRESSION) ];
3566
3567 This pragma may be specified for protected types or objects. It specifies that
3568 the implementation of protected operations must be implemented without locks.
3569 Compilation fails if the compiler cannot generate lock-free code for the
3570 operations.
3571
3572 The current conditions required to support this pragma are:
3573
3574 * Protected type declarations may not contain entries
3575 * Protected subprogram declarations may not have nonelementary parameters
3576
3577 In addition, each protected subprogram body must satisfy:
3578
3579 * May reference only one protected component
3580 * May not reference nonconstant entities outside the protected subprogram
3581 scope
3582 * May not contain address representation items, allocators, or quantified
3583 expressions
3584 * May not contain delay, goto, loop, or procedure-call statements
3585 * May not contain exported and imported entities
3586 * May not dereferenced access values
3587 * Function calls and attribute references must be static
3588
3589 If the Lock_Free aspect is specified to be True for a protected unit
3590 and the Ceiling_Locking locking policy is in effect, then the run-time
3591 actions associated with the Ceiling_Locking locking policy (described in
3592 Ada RM D.3) are not performed when a protected operation of the protected
3593 unit is executed.
3594
3595 Pragma Loop_Invariant
3596 =====================
3597
3598 Syntax:
3599
3600
3601 .. code-block:: ada
3602
3603 pragma Loop_Invariant ( boolean_EXPRESSION );
3604
3605
3606 The effect of this pragma is similar to that of pragma ``Assert``,
3607 except that in an ``Assertion_Policy`` pragma, the identifier
3608 ``Loop_Invariant`` is used to control whether it is ignored or checked
3609 (or disabled).
3610
3611 ``Loop_Invariant`` can only appear as one of the items in the sequence
3612 of statements of a loop body, or nested inside block statements that
3613 appear in the sequence of statements of a loop body.
3614 The intention is that it be used to
3615 represent a "loop invariant" assertion, i.e. something that is true each
3616 time through the loop, and which can be used to show that the loop is
3617 achieving its purpose.
3618
3619 Multiple ``Loop_Invariant`` and ``Loop_Variant`` pragmas that
3620 apply to the same loop should be grouped in the same sequence of
3621 statements.
3622
3623 To aid in writing such invariants, the special attribute ``Loop_Entry``
3624 may be used to refer to the value of an expression on entry to the loop. This
3625 attribute can only be used within the expression of a ``Loop_Invariant``
3626 pragma. For full details, see documentation of attribute ``Loop_Entry``.
3627
3628 Pragma Loop_Optimize
3629 ====================
3630
3631 Syntax:
3632
3633
3634 ::
3635
3636 pragma Loop_Optimize (OPTIMIZATION_HINT {, OPTIMIZATION_HINT});
3637
3638 OPTIMIZATION_HINT ::= Ivdep | No_Unroll | Unroll | No_Vector | Vector
3639
3640
3641 This pragma must appear immediately within a loop statement. It allows the
3642 programmer to specify optimization hints for the enclosing loop. The hints
3643 are not mutually exclusive and can be freely mixed, but not all combinations
3644 will yield a sensible outcome.
3645
3646 There are five supported optimization hints for a loop:
3647
3648 * Ivdep
3649
3650 The programmer asserts that there are no loop-carried dependencies
3651 which would prevent consecutive iterations of the loop from being
3652 executed simultaneously.
3653
3654 * No_Unroll
3655
3656 The loop must not be unrolled. This is a strong hint: the compiler will not
3657 unroll a loop marked with this hint.
3658
3659 * Unroll
3660
3661 The loop should be unrolled. This is a weak hint: the compiler will try to
3662 apply unrolling to this loop preferably to other optimizations, notably
3663 vectorization, but there is no guarantee that the loop will be unrolled.
3664
3665 * No_Vector
3666
3667 The loop must not be vectorized. This is a strong hint: the compiler will not
3668 vectorize a loop marked with this hint.
3669
3670 * Vector
3671
3672 The loop should be vectorized. This is a weak hint: the compiler will try to
3673 apply vectorization to this loop preferably to other optimizations, notably
3674 unrolling, but there is no guarantee that the loop will be vectorized.
3675
3676
3677 These hints do not remove the need to pass the appropriate switches to the
3678 compiler in order to enable the relevant optimizations, that is to say
3679 *-funroll-loops* for unrolling and *-ftree-vectorize* for
3680 vectorization.
3681
3682 Pragma Loop_Variant
3683 ===================
3684
3685 Syntax:
3686
3687
3688 ::
3689
3690 pragma Loop_Variant ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
3691 LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
3692 CHANGE_DIRECTION ::= Increases | Decreases
3693
3694
3695 ``Loop_Variant`` can only appear as one of the items in the sequence
3696 of statements of a loop body, or nested inside block statements that
3697 appear in the sequence of statements of a loop body.
3698 It allows the specification of quantities which must always
3699 decrease or increase in successive iterations of the loop. In its simplest
3700 form, just one expression is specified, whose value must increase or decrease
3701 on each iteration of the loop.
3702
3703 In a more complex form, multiple arguments can be given which are interpreted
3704 in a nesting lexicographic manner. For example:
3705
3706 .. code-block:: ada
3707
3708 pragma Loop_Variant (Increases => X, Decreases => Y);
3709
3710
3711 specifies that each time through the loop either X increases, or X stays
3712 the same and Y decreases. A ``Loop_Variant`` pragma ensures that the
3713 loop is making progress. It can be useful in helping to show informally
3714 or prove formally that the loop always terminates.
3715
3716 ``Loop_Variant`` is an assertion whose effect can be controlled using
3717 an ``Assertion_Policy`` with a check name of ``Loop_Variant``. The
3718 policy can be ``Check`` to enable the loop variant check, ``Ignore``
3719 to ignore the check (in which case the pragma has no effect on the program),
3720 or ``Disable`` in which case the pragma is not even checked for correct
3721 syntax.
3722
3723 Multiple ``Loop_Invariant`` and ``Loop_Variant`` pragmas that
3724 apply to the same loop should be grouped in the same sequence of
3725 statements.
3726
3727 The ``Loop_Entry`` attribute may be used within the expressions of the
3728 ``Loop_Variant`` pragma to refer to values on entry to the loop.
3729
3730 Pragma Machine_Attribute
3731 ========================
3732
3733 Syntax:
3734
3735
3736 ::
3737
3738 pragma Machine_Attribute (
3739 [Entity =>] LOCAL_NAME,
3740 [Attribute_Name =>] static_string_EXPRESSION
3741 [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
3742
3743
3744 Machine-dependent attributes can be specified for types and/or
3745 declarations. This pragma is semantically equivalent to
3746 :samp:`__attribute__(({attribute_name}))` (if ``info`` is not
3747 specified) or :samp:`__attribute__(({attribute_name(info})))`
3748 or :samp:`__attribute__(({attribute_name(info,...})))` in GNU C,
3749 where *attribute_name* is recognized by the compiler middle-end
3750 or the ``TARGET_ATTRIBUTE_TABLE`` machine specific macro. Note
3751 that a string literal for the optional parameter ``info`` or the
3752 following ones is transformed by default into an identifier,
3753 which may make this pragma unusable for some attributes.
3754 For further information see :title:`GNU Compiler Collection (GCC) Internals`.
3755
3756 Pragma Main
3757 ===========
3758
3759 Syntax::
3760
3761 pragma Main
3762 (MAIN_OPTION [, MAIN_OPTION]);
3763
3764 MAIN_OPTION ::=
3765 [Stack_Size =>] static_integer_EXPRESSION
3766 | [Task_Stack_Size_Default =>] static_integer_EXPRESSION
3767 | [Time_Slicing_Enabled =>] static_boolean_EXPRESSION
3768
3769
3770 This pragma is provided for compatibility with OpenVMS VAX Systems. It has
3771 no effect in GNAT, other than being syntax checked.
3772
3773 Pragma Main_Storage
3774 ===================
3775
3776 Syntax::
3777
3778 pragma Main_Storage
3779 (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
3780
3781 MAIN_STORAGE_OPTION ::=
3782 [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
3783 | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
3784
3785
3786 This pragma is provided for compatibility with OpenVMS VAX Systems. It has
3787 no effect in GNAT, other than being syntax checked.
3788
3789 .. _Pragma-Max_Queue_Length:
3790
3791 Pragma Max_Queue_Length
3792 =======================
3793
3794 Syntax::
3795
3796 pragma Max_Queue_Length (static_integer_EXPRESSION);
3797
3798
3799 This pragma is used to specify the maximum callers per entry queue for
3800 individual protected entries and entry families. It accepts a single
3801 integer (-1 or more) as a parameter and must appear after the declaration of an
3802 entry.
3803
3804 A value of -1 represents no additional restriction on queue length.
3805
3806 Pragma No_Body
3807 ==============
3808
3809 Syntax:
3810
3811
3812 .. code-block:: ada
3813
3814 pragma No_Body;
3815
3816
3817 There are a number of cases in which a package spec does not require a body,
3818 and in fact a body is not permitted. GNAT will not permit the spec to be
3819 compiled if there is a body around. The pragma No_Body allows you to provide
3820 a body file, even in a case where no body is allowed. The body file must
3821 contain only comments and a single No_Body pragma. This is recognized by
3822 the compiler as indicating that no body is logically present.
3823
3824 This is particularly useful during maintenance when a package is modified in
3825 such a way that a body needed before is no longer needed. The provision of a
3826 dummy body with a No_Body pragma ensures that there is no interference from
3827 earlier versions of the package body.
3828
3829 .. _Pragma-No_Caching:
3830
3831 Pragma No_Caching
3832 =================
3833
3834 Syntax:
3835
3836 .. code-block:: ada
3837
3838 pragma No_Caching [ (static_boolean_EXPRESSION) ];
3839
3840 For the semantics of this pragma, see the entry for aspect ``No_Caching`` in
3841 the SPARK 2014 Reference Manual, section 7.1.2.
3842
3843 Pragma No_Component_Reordering
3844 ==============================
3845
3846 Syntax:
3847
3848
3849 ::
3850
3851 pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
3852
3853
3854 ``type_LOCAL_NAME`` must refer to a record type declaration in the current
3855 declarative part. The effect is to preclude any reordering of components
3856 for the layout of the record, i.e. the record is laid out by the compiler
3857 in the order in which the components are declared textually. The form with
3858 no argument is a configuration pragma which applies to all record types
3859 declared in units to which the pragma applies and there is a requirement
3860 that this pragma be used consistently within a partition.
3861
3862 .. _Pragma-No_Elaboration_Code_All:
3863
3864 Pragma No_Elaboration_Code_All
3865 ==============================
3866
3867 Syntax:
3868
3869
3870 ::
3871
3872 pragma No_Elaboration_Code_All [(program_unit_NAME)];
3873
3874
3875 This is a program unit pragma (there is also an equivalent aspect of the
3876 same name) that establishes the restriction ``No_Elaboration_Code`` for
3877 the current unit and any extended main source units (body and subunits).
3878 It also has the effect of enforcing a transitive application of this
3879 aspect, so that if any unit is implicitly or explicitly with'ed by the
3880 current unit, it must also have the `No_Elaboration_Code_All` aspect set.
3881 It may be applied to package or subprogram specs or their generic versions.
3882
3883 Pragma No_Heap_Finalization
3884 ===========================
3885
3886 Syntax:
3887
3888
3889 ::
3890
3891 pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
3892
3893
3894 Pragma ``No_Heap_Finalization`` may be used as a configuration pragma or as a
3895 type-specific pragma.
3896
3897 In its configuration form, the pragma must appear within a configuration file
3898 such as gnat.adc, without an argument. The pragma suppresses the call to
3899 ``Finalize`` for heap-allocated objects created through library-level named
3900 access-to-object types in cases where the designated type requires finalization
3901 actions.
3902
3903 In its type-specific form, the argument of the pragma must denote a
3904 library-level named access-to-object type. The pragma suppresses the call to
3905 ``Finalize`` for heap-allocated objects created through the specific access type
3906 in cases where the designated type requires finalization actions.
3907
3908 It is still possible to finalize such heap-allocated objects by explicitly
3909 deallocating them.
3910
3911 A library-level named access-to-object type declared within a generic unit will
3912 lose its ``No_Heap_Finalization`` pragma when the corresponding instance does not
3913 appear at the library level.
3914
3915 .. _Pragma-No_Inline:
3916
3917 Pragma No_Inline
3918 ================
3919
3920 Syntax:
3921
3922
3923 ::
3924
3925 pragma No_Inline (NAME {, NAME});
3926
3927
3928 This pragma suppresses inlining for the callable entity or the instances of
3929 the generic subprogram designated by ``NAME``, including inlining that
3930 results from the use of pragma ``Inline``. This pragma is always active,
3931 in particular it is not subject to the use of option *-gnatn* or
3932 *-gnatN*. It is illegal to specify both pragma ``No_Inline`` and
3933 pragma ``Inline_Always`` for the same ``NAME``.
3934
3935 .. _Pragma-No_Raise:
3936
3937 Pragma No_Raise
3938 ===============
3939
3940 Syntax:
3941
3942
3943 ::
3944
3945 pragma No_Raise (subprogram_LOCAL_NAME {, subprogram_LOCAL_NAME});
3946
3947
3948 Each ``subprogram_LOCAL_NAME`` argument must refer to one or more subprogram
3949 declarations in the current declarative part. A subprogram to which this
3950 pragma is applied may not raise an exception that is not caught within it.
3951 An implementation-defined check named `Raise_Check` is associated with the
3952 pragma, and `Program_Error` is raised upon its failure (see RM 11.5(19/5)).
3953
3954 Pragma No_Return
3955 ================
3956
3957 Syntax:
3958
3959
3960 ::
3961
3962 pragma No_Return (procedure_LOCAL_NAME {, procedure_LOCAL_NAME});
3963
3964
3965 Each ``procedure_LOCAL_NAME`` argument must refer to one or more procedure
3966 declarations in the current declarative part. A procedure to which this
3967 pragma is applied may not contain any explicit ``return`` statements.
3968 In addition, if the procedure contains any implicit returns from falling
3969 off the end of a statement sequence, then execution of that implicit
3970 return will cause Program_Error to be raised.
3971
3972 One use of this pragma is to identify procedures whose only purpose is to raise
3973 an exception. Another use of this pragma is to suppress incorrect warnings
3974 about missing returns in functions, where the last statement of a function
3975 statement sequence is a call to such a procedure.
3976
3977 Note that in Ada 2005 mode, this pragma is part of the language. It is
3978 available in all earlier versions of Ada as an implementation-defined
3979 pragma.
3980
3981 Pragma No_Strict_Aliasing
3982 =========================
3983
3984 Syntax:
3985
3986
3987 ::
3988
3989 pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
3990
3991
3992 ``type_LOCAL_NAME`` must refer to an access type
3993 declaration in the current declarative part. The effect is to inhibit
3994 strict aliasing optimization for the given type. The form with no
3995 arguments is a configuration pragma which applies to all access types
3996 declared in units to which the pragma applies. For a detailed
3997 description of the strict aliasing optimization, and the situations
3998 in which it must be suppressed, see the section on Optimization and Strict Aliasing
3999 in the :title:`GNAT User's Guide`.
4000
4001 This pragma currently has no effects on access to unconstrained array types.
4002
4003 .. _Pragma-No_Tagged_Streams:
4004
4005 Pragma No_Tagged_Streams
4006 ========================
4007
4008 Syntax:
4009
4010
4011 ::
4012
4013 pragma No_Tagged_Streams [([Entity =>] tagged_type_LOCAL_NAME)];
4014
4015
4016 Normally when a tagged type is introduced using a full type declaration,
4017 part of the processing includes generating stream access routines to be
4018 used by stream attributes referencing the type (or one of its subtypes
4019 or derived types). This can involve the generation of significant amounts
4020 of code which is wasted space if stream routines are not needed for the
4021 type in question.
4022
4023 The ``No_Tagged_Streams`` pragma causes the generation of these stream
4024 routines to be skipped, and any attempt to use stream operations on
4025 types subject to this pragma will be statically rejected as illegal.
4026
4027 There are two forms of the pragma. The form with no arguments must appear
4028 in a declarative sequence or in the declarations of a package spec. This
4029 pragma affects all subsequent root tagged types declared in the declaration
4030 sequence, and specifies that no stream routines be generated. The form with
4031 an argument (for which there is also a corresponding aspect) specifies a
4032 single root tagged type for which stream routines are not to be generated.
4033
4034 Once the pragma has been given for a particular root tagged type, all subtypes
4035 and derived types of this type inherit the pragma automatically, so the effect
4036 applies to a complete hierarchy (this is necessary to deal with the class-wide
4037 dispatching versions of the stream routines).
4038
4039 When pragmas ``Discard_Names`` and ``No_Tagged_Streams`` are simultaneously
4040 applied to a tagged type its Expanded_Name and External_Tag are initialized
4041 with empty strings. This is useful to avoid exposing entity names at binary
4042 level but has a negative impact on the debuggability of tagged types.
4043
4044 Pragma Normalize_Scalars
4045 ========================
4046
4047 Syntax:
4048
4049
4050 .. code-block:: ada
4051
4052 pragma Normalize_Scalars;
4053
4054
4055 This is a language defined pragma which is fully implemented in GNAT. The
4056 effect is to cause all scalar objects that are not otherwise initialized
4057 to be initialized. The initial values are implementation dependent and
4058 are as follows:
4059
4060
4061
4062 *Standard.Character*
4063 Objects whose root type is Standard.Character are initialized to
4064 Character'Last unless the subtype range excludes NUL (in which case
4065 NUL is used). This choice will always generate an invalid value if
4066 one exists.
4067
4068
4069 *Standard.Wide_Character*
4070 Objects whose root type is Standard.Wide_Character are initialized to
4071 Wide_Character'Last unless the subtype range excludes NUL (in which case
4072 NUL is used). This choice will always generate an invalid value if
4073 one exists.
4074
4075
4076 *Standard.Wide_Wide_Character*
4077 Objects whose root type is Standard.Wide_Wide_Character are initialized to
4078 the invalid value 16#FFFF_FFFF# unless the subtype range excludes NUL (in
4079 which case NUL is used). This choice will always generate an invalid value if
4080 one exists.
4081
4082
4083 *Integer types*
4084 Objects of an integer type are treated differently depending on whether
4085 negative values are present in the subtype. If no negative values are
4086 present, then all one bits is used as the initial value except in the
4087 special case where zero is excluded from the subtype, in which case
4088 all zero bits are used. This choice will always generate an invalid
4089 value if one exists.
4090
4091 For subtypes with negative values present, the largest negative number
4092 is used, except in the unusual case where this largest negative number
4093 is in the subtype, and the largest positive number is not, in which case
4094 the largest positive value is used. This choice will always generate
4095 an invalid value if one exists.
4096
4097
4098 *Floating-Point Types*
4099 Objects of all floating-point types are initialized to all 1-bits. For
4100 standard IEEE format, this corresponds to a NaN (not a number) which is
4101 indeed an invalid value.
4102
4103
4104 *Fixed-Point Types*
4105 Objects of all fixed-point types are treated as described above for integers,
4106 with the rules applying to the underlying integer value used to represent
4107 the fixed-point value.
4108
4109
4110 *Modular types*
4111 Objects of a modular type are initialized to all one bits, except in
4112 the special case where zero is excluded from the subtype, in which
4113 case all zero bits are used. This choice will always generate an
4114 invalid value if one exists.
4115
4116
4117 *Enumeration types*
4118 Objects of an enumeration type are initialized to all one-bits, i.e., to
4119 the value ``2 ** typ'Size - 1`` unless the subtype excludes the literal
4120 whose Pos value is zero, in which case a code of zero is used. This choice
4121 will always generate an invalid value if one exists.
4122
4123 .. _Pragma_Obsolescent:
4124
4125 Pragma Obsolescent
4126 ==================
4127
4128 Syntax:
4129
4130
4131 ::
4132
4133 pragma Obsolescent;
4134
4135 pragma Obsolescent (
4136 [Message =>] static_string_EXPRESSION
4137 [,[Version =>] Ada_05]);
4138
4139 pragma Obsolescent (
4140 [Entity =>] NAME
4141 [,[Message =>] static_string_EXPRESSION
4142 [,[Version =>] Ada_05]]);
4143
4144
4145 This pragma can occur immediately following a declaration of an entity,
4146 including the case of a record component. If no Entity argument is present,
4147 then this declaration is the one to which the pragma applies. If an Entity
4148 parameter is present, it must either match the name of the entity in this
4149 declaration, or alternatively, the pragma can immediately follow an enumeration
4150 type declaration, where the Entity argument names one of the enumeration
4151 literals.
4152
4153 This pragma is used to indicate that the named entity
4154 is considered obsolescent and should not be used. Typically this is
4155 used when an API must be modified by eventually removing or modifying
4156 existing subprograms or other entities. The pragma can be used at an
4157 intermediate stage when the entity is still present, but will be
4158 removed later.
4159
4160 The effect of this pragma is to output a warning message on a reference to
4161 an entity thus marked that the subprogram is obsolescent if the appropriate
4162 warning option in the compiler is activated. If the ``Message`` parameter is
4163 present, then a second warning message is given containing this text. In
4164 addition, a reference to the entity is considered to be a violation of pragma
4165 ``Restrictions (No_Obsolescent_Features)``.
4166
4167 This pragma can also be used as a program unit pragma for a package,
4168 in which case the entity name is the name of the package, and the
4169 pragma indicates that the entire package is considered
4170 obsolescent. In this case a client ``with``\ ing such a package
4171 violates the restriction, and the ``with`` clause is
4172 flagged with warnings if the warning option is set.
4173
4174 If the ``Version`` parameter is present (which must be exactly
4175 the identifier ``Ada_05``, no other argument is allowed), then the
4176 indication of obsolescence applies only when compiling in Ada 2005
4177 mode. This is primarily intended for dealing with the situations
4178 in the predefined library where subprograms or packages
4179 have become defined as obsolescent in Ada 2005
4180 (e.g., in ``Ada.Characters.Handling``), but may be used anywhere.
4181
4182 The following examples show typical uses of this pragma:
4183
4184
4185 .. code-block:: ada
4186
4187 package p is
4188 pragma Obsolescent (p, Message => "use pp instead of p");
4189 end p;
4190
4191 package q is
4192 procedure q2;
4193 pragma Obsolescent ("use q2new instead");
4194
4195 type R is new integer;
4196 pragma Obsolescent
4197 (Entity => R,
4198 Message => "use RR in Ada 2005",
4199 Version => Ada_05);
4200
4201 type M is record
4202 F1 : Integer;
4203 F2 : Integer;
4204 pragma Obsolescent;
4205 F3 : Integer;
4206 end record;
4207
4208 type E is (a, bc, 'd', quack);
4209 pragma Obsolescent (Entity => bc)
4210 pragma Obsolescent (Entity => 'd')
4211
4212 function "+"
4213 (a, b : character) return character;
4214 pragma Obsolescent (Entity => "+");
4215 end;
4216
4217
4218 Note that, as for all pragmas, if you use a pragma argument identifier,
4219 then all subsequent parameters must also use a pragma argument identifier.
4220 So if you specify ``Entity =>`` for the ``Entity`` argument, and a ``Message``
4221 argument is present, it must be preceded by ``Message =>``.
4222
4223 Pragma Optimize_Alignment
4224 =========================
4225 .. index:: Alignment, default settings
4226
4227 Syntax:
4228
4229
4230 .. code-block:: ada
4231
4232 pragma Optimize_Alignment (TIME | SPACE | OFF);
4233
4234
4235 This is a configuration pragma which affects the choice of default alignments
4236 for types and objects where no alignment is explicitly specified. There is a
4237 time/space trade-off in the selection of these values. Large alignments result
4238 in more efficient code, at the expense of larger data space, since sizes have
4239 to be increased to match these alignments. Smaller alignments save space, but
4240 the access code is slower. The normal choice of default alignments for types
4241 and individual alignment promotions for objects (which is what you get if you
4242 do not use this pragma, or if you use an argument of OFF), tries to balance
4243 these two requirements.
4244
4245 Specifying SPACE causes smaller default alignments to be chosen in two cases.
4246 First any packed record is given an alignment of 1. Second, if a size is given
4247 for the type, then the alignment is chosen to avoid increasing this size. For
4248 example, consider:
4249
4250
4251 .. code-block:: ada
4252
4253 type R is record
4254 X : Integer;
4255 Y : Character;
4256 end record;
4257
4258 for R'Size use 5*8;
4259
4260
4261 In the default mode, this type gets an alignment of 4, so that access to the
4262 Integer field X are efficient. But this means that objects of the type end up
4263 with a size of 8 bytes. This is a valid choice, since sizes of objects are
4264 allowed to be bigger than the size of the type, but it can waste space if for
4265 example fields of type R appear in an enclosing record. If the above type is
4266 compiled in ``Optimize_Alignment (Space)`` mode, the alignment is set to 1.
4267
4268 However, there is one case in which SPACE is ignored. If a variable length
4269 record (that is a discriminated record with a component which is an array
4270 whose length depends on a discriminant), has a pragma Pack, then it is not
4271 in general possible to set the alignment of such a record to one, so the
4272 pragma is ignored in this case (with a warning).
4273
4274 Specifying SPACE also disables alignment promotions for standalone objects,
4275 which occur when the compiler increases the alignment of a specific object
4276 without changing the alignment of its type.
4277
4278 Specifying SPACE also disables component reordering in unpacked record types,
4279 which can result in larger sizes in order to meet alignment requirements.
4280
4281 Specifying TIME causes larger default alignments to be chosen in the case of
4282 small types with sizes that are not a power of 2. For example, consider:
4283
4284
4285 .. code-block:: ada
4286
4287 type R is record
4288 A : Character;
4289 B : Character;
4290 C : Boolean;
4291 end record;
4292
4293 pragma Pack (R);
4294 for R'Size use 17;
4295
4296
4297 The default alignment for this record is normally 1, but if this type is
4298 compiled in ``Optimize_Alignment (Time)`` mode, then the alignment is set
4299 to 4, which wastes space for objects of the type, since they are now 4 bytes
4300 long, but results in more efficient access when the whole record is referenced.
4301
4302 As noted above, this is a configuration pragma, and there is a requirement
4303 that all units in a partition be compiled with a consistent setting of the
4304 optimization setting. This would normally be achieved by use of a configuration
4305 pragma file containing the appropriate setting. The exception to this rule is
4306 that units with an explicit configuration pragma in the same file as the source
4307 unit are excluded from the consistency check, as are all predefined units. The
4308 latter are compiled by default in pragma Optimize_Alignment (Off) mode if no
4309 pragma appears at the start of the file.
4310
4311 Pragma Ordered
4312 ==============
4313
4314 Syntax:
4315
4316
4317 .. code-block:: ada
4318
4319 pragma Ordered (enumeration_first_subtype_LOCAL_NAME);
4320
4321
4322 Most enumeration types are from a conceptual point of view unordered.
4323 For example, consider:
4324
4325
4326 .. code-block:: ada
4327
4328 type Color is (Red, Blue, Green, Yellow);
4329
4330
4331 By Ada semantics ``Blue > Red`` and ``Green > Blue``,
4332 but really these relations make no sense; the enumeration type merely
4333 specifies a set of possible colors, and the order is unimportant.
4334
4335 For unordered enumeration types, it is generally a good idea if
4336 clients avoid comparisons (other than equality or inequality) and
4337 explicit ranges. (A *client* is a unit where the type is referenced,
4338 other than the unit where the type is declared, its body, and its subunits.)
4339 For example, if code buried in some client says:
4340
4341
4342 .. code-block:: ada
4343
4344 if Current_Color < Yellow then ...
4345 if Current_Color in Blue .. Green then ...
4346
4347
4348 then the client code is relying on the order, which is undesirable.
4349 It makes the code hard to read and creates maintenance difficulties if
4350 entries have to be added to the enumeration type. Instead,
4351 the code in the client should list the possibilities, or an
4352 appropriate subtype should be declared in the unit that declares
4353 the original enumeration type. E.g., the following subtype could
4354 be declared along with the type ``Color``:
4355
4356
4357 .. code-block:: ada
4358
4359 subtype RBG is Color range Red .. Green;
4360
4361
4362 and then the client could write:
4363
4364
4365 .. code-block:: ada
4366
4367 if Current_Color in RBG then ...
4368 if Current_Color = Blue or Current_Color = Green then ...
4369
4370
4371 However, some enumeration types are legitimately ordered from a conceptual
4372 point of view. For example, if you declare:
4373
4374
4375 .. code-block:: ada
4376
4377 type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
4378
4379
4380 then the ordering imposed by the language is reasonable, and
4381 clients can depend on it, writing for example:
4382
4383
4384 .. code-block:: ada
4385
4386 if D in Mon .. Fri then ...
4387 if D < Wed then ...
4388
4389
4390 The pragma *Ordered* is provided to mark enumeration types that
4391 are conceptually ordered, alerting the reader that clients may depend
4392 on the ordering. GNAT provides a pragma to mark enumerations as ordered
4393 rather than one to mark them as unordered, since in our experience,
4394 the great majority of enumeration types are conceptually unordered.
4395
4396 The types ``Boolean``, ``Character``, ``Wide_Character``,
4397 and ``Wide_Wide_Character``
4398 are considered to be ordered types, so each is declared with a
4399 pragma ``Ordered`` in package ``Standard``.
4400
4401 Normally pragma ``Ordered`` serves only as documentation and a guide for
4402 coding standards, but GNAT provides a warning switch *-gnatw.u* that
4403 requests warnings for inappropriate uses (comparisons and explicit
4404 subranges) for unordered types. If this switch is used, then any
4405 enumeration type not marked with pragma ``Ordered`` will be considered
4406 as unordered, and will generate warnings for inappropriate uses.
4407
4408 Note that generic types are not considered ordered or unordered (since the
4409 template can be instantiated for both cases), so we never generate warnings
4410 for the case of generic enumerated types.
4411
4412 For additional information please refer to the description of the
4413 *-gnatw.u* switch in the GNAT User's Guide.
4414
4415 Pragma Overflow_Mode
4416 ====================
4417
4418 Syntax:
4419
4420
4421 ::
4422
4423 pragma Overflow_Mode
4424 ( [General =>] MODE
4425 [,[Assertions =>] MODE]);
4426
4427 MODE ::= STRICT | MINIMIZED | ELIMINATED
4428
4429
4430 This pragma sets the current overflow mode to the given setting. For details
4431 of the meaning of these modes, please refer to the
4432 'Overflow Check Handling in GNAT' appendix in the
4433 GNAT User's Guide. If only the ``General`` parameter is present,
4434 the given mode applies to all expressions. If both parameters are present,
4435 the ``General`` mode applies to expressions outside assertions, and
4436 the ``Eliminated`` mode applies to expressions within assertions.
4437
4438 The case of the ``MODE`` parameter is ignored,
4439 so ``MINIMIZED``, ``Minimized`` and
4440 ``minimized`` all have the same effect.
4441
4442 The ``Overflow_Mode`` pragma has the same scoping and placement
4443 rules as pragma ``Suppress``, so it can occur either as a
4444 configuration pragma, specifying a default for the whole
4445 program, or in a declarative scope, where it applies to the
4446 remaining declarations and statements in that scope.
4447
4448 The pragma ``Suppress (Overflow_Check)`` suppresses
4449 overflow checking, but does not affect the overflow mode.
4450
4451 The pragma ``Unsuppress (Overflow_Check)`` unsuppresses (enables)
4452 overflow checking, but does not affect the overflow mode.
4453
4454 Pragma Overriding_Renamings
4455 ===========================
4456 .. index:: Rational profile
4457
4458 .. index:: Rational compatibility
4459
4460 Syntax:
4461
4462
4463 .. code-block:: ada
4464
4465 pragma Overriding_Renamings;
4466
4467
4468 This is a GNAT configuration pragma to simplify porting
4469 legacy code accepted by the Rational
4470 Ada compiler. In the presence of this pragma, a renaming declaration that
4471 renames an inherited operation declared in the same scope is legal if selected
4472 notation is used as in:
4473
4474
4475 .. code-block:: ada
4476
4477 pragma Overriding_Renamings;
4478 ...
4479 package R is
4480 function F (..);
4481 ...
4482 function F (..) renames R.F;
4483 end R;
4484
4485
4486 even though
4487 RM 8.3 (15) stipulates that an overridden operation is not visible within the
4488 declaration of the overriding operation.
4489
4490 .. _Pragma-Part_Of:
4491
4492 Pragma Part_Of
4493 ==============
4494
4495 Syntax:
4496
4497 .. code-block:: ada
4498
4499 pragma Part_Of (ABSTRACT_STATE);
4500
4501 ABSTRACT_STATE ::= NAME
4502
4503 For the semantics of this pragma, see the entry for aspect ``Part_Of`` in the
4504 SPARK 2014 Reference Manual, section 7.2.6.
4505
4506 Pragma Partition_Elaboration_Policy
4507 ===================================
4508
4509 Syntax:
4510
4511
4512 ::
4513
4514 pragma Partition_Elaboration_Policy (POLICY_IDENTIFIER);
4515
4516 POLICY_IDENTIFIER ::= Concurrent | Sequential
4517
4518
4519 This pragma is standard in Ada 2005, but is available in all earlier
4520 versions of Ada as an implementation-defined pragma.
4521 See Ada 2012 Reference Manual for details.
4522
4523 Pragma Passive
4524 ==============
4525
4526 Syntax:
4527
4528
4529 ::
4530
4531 pragma Passive [(Semaphore | No)];
4532
4533
4534 Syntax checked, but otherwise ignored by GNAT. This is recognized for
4535 compatibility with DEC Ada 83 implementations, where it is used within a
4536 task definition to request that a task be made passive. If the argument
4537 ``Semaphore`` is present, or the argument is omitted, then DEC Ada 83
4538 treats the pragma as an assertion that the containing task is passive
4539 and that optimization of context switch with this task is permitted and
4540 desired. If the argument ``No`` is present, the task must not be
4541 optimized. GNAT does not attempt to optimize any tasks in this manner
4542 (since protected objects are available in place of passive tasks).
4543
4544 For more information on the subject of passive tasks, see the section
4545 'Passive Task Optimization' in the GNAT Users Guide.
4546
4547 .. _Pragma-Persistent_BSS:
4548
4549 Pragma Persistent_BSS
4550 =====================
4551
4552 Syntax:
4553
4554
4555 ::
4556
4557 pragma Persistent_BSS [(object_LOCAL_NAME)]
4558
4559
4560 This pragma allows selected objects to be placed in the ``.persistent_bss``
4561 section. On some targets the linker and loader provide for special
4562 treatment of this section, allowing a program to be reloaded without
4563 affecting the contents of this data (hence the name persistent).
4564
4565 There are two forms of usage. If an argument is given, it must be the
4566 local name of a library-level object, with no explicit initialization
4567 and whose type is potentially persistent. If no argument is given, then
4568 the pragma is a configuration pragma, and applies to all library-level
4569 objects with no explicit initialization of potentially persistent types.
4570
4571 A potentially persistent type is a scalar type, or an untagged,
4572 non-discriminated record, all of whose components have no explicit
4573 initialization and are themselves of a potentially persistent type,
4574 or an array, all of whose constraints are static, and whose component
4575 type is potentially persistent.
4576
4577 If this pragma is used on a target where this feature is not supported,
4578 then the pragma will be ignored. See also ``pragma Linker_Section``.
4579
4580 Pragma Post
4581 ===========
4582 .. index:: Post
4583
4584 .. index:: Checks, postconditions
4585
4586
4587 Syntax:
4588
4589
4590 .. code-block:: ada
4591
4592 pragma Post (Boolean_Expression);
4593
4594
4595 The ``Post`` pragma is intended to be an exact replacement for
4596 the language-defined
4597 ``Post`` aspect, and shares its restrictions and semantics.
4598 It must appear either immediately following the corresponding
4599 subprogram declaration (only other pragmas may intervene), or
4600 if there is no separate subprogram declaration, then it can
4601 appear at the start of the declarations in a subprogram body
4602 (preceded only by other pragmas).
4603
4604 Pragma Postcondition
4605 ====================
4606 .. index:: Postcondition
4607
4608 .. index:: Checks, postconditions
4609
4610
4611 Syntax:
4612
4613
4614 ::
4615
4616 pragma Postcondition (
4617 [Check =>] Boolean_Expression
4618 [,[Message =>] String_Expression]);
4619
4620
4621 The ``Postcondition`` pragma allows specification of automatic
4622 postcondition checks for subprograms. These checks are similar to
4623 assertions, but are automatically inserted just prior to the return
4624 statements of the subprogram with which they are associated (including
4625 implicit returns at the end of procedure bodies and associated
4626 exception handlers).
4627
4628 In addition, the boolean expression which is the condition which
4629 must be true may contain references to function'Result in the case
4630 of a function to refer to the returned value.
4631
4632 ``Postcondition`` pragmas may appear either immediately following the
4633 (separate) declaration of a subprogram, or at the start of the
4634 declarations of a subprogram body. Only other pragmas may intervene
4635 (that is appear between the subprogram declaration and its
4636 postconditions, or appear before the postcondition in the
4637 declaration sequence in a subprogram body). In the case of a
4638 postcondition appearing after a subprogram declaration, the
4639 formal arguments of the subprogram are visible, and can be
4640 referenced in the postcondition expressions.
4641
4642 The postconditions are collected and automatically tested just
4643 before any return (implicit or explicit) in the subprogram body.
4644 A postcondition is only recognized if postconditions are active
4645 at the time the pragma is encountered. The compiler switch *gnata*
4646 turns on all postconditions by default, and pragma ``Check_Policy``
4647 with an identifier of ``Postcondition`` can also be used to
4648 control whether postconditions are active.
4649
4650 The general approach is that postconditions are placed in the spec
4651 if they represent functional aspects which make sense to the client.
4652 For example we might have:
4653
4654
4655 .. code-block:: ada
4656
4657 function Direction return Integer;
4658 pragma Postcondition
4659 (Direction'Result = +1
4660 or else
4661 Direction'Result = -1);
4662
4663
4664 which serves to document that the result must be +1 or -1, and
4665 will test that this is the case at run time if postcondition
4666 checking is active.
4667
4668 Postconditions within the subprogram body can be used to
4669 check that some internal aspect of the implementation,
4670 not visible to the client, is operating as expected.
4671 For instance if a square root routine keeps an internal
4672 counter of the number of times it is called, then we
4673 might have the following postcondition:
4674
4675
4676 .. code-block:: ada
4677
4678 Sqrt_Calls : Natural := 0;
4679
4680 function Sqrt (Arg : Float) return Float is
4681 pragma Postcondition
4682 (Sqrt_Calls = Sqrt_Calls'Old + 1);
4683 ...
4684 end Sqrt
4685
4686
4687 As this example, shows, the use of the ``Old`` attribute
4688 is often useful in postconditions to refer to the state on
4689 entry to the subprogram.
4690
4691 Note that postconditions are only checked on normal returns
4692 from the subprogram. If an abnormal return results from
4693 raising an exception, then the postconditions are not checked.
4694
4695 If a postcondition fails, then the exception
4696 ``System.Assertions.Assert_Failure`` is raised. If
4697 a message argument was supplied, then the given string
4698 will be used as the exception message. If no message
4699 argument was supplied, then the default message has
4700 the form "Postcondition failed at file_name:line". The
4701 exception is raised in the context of the subprogram
4702 body, so it is possible to catch postcondition failures
4703 within the subprogram body itself.
4704
4705 Within a package spec, normal visibility rules
4706 in Ada would prevent forward references within a
4707 postcondition pragma to functions defined later in
4708 the same package. This would introduce undesirable
4709 ordering constraints. To avoid this problem, all
4710 postcondition pragmas are analyzed at the end of
4711 the package spec, allowing forward references.
4712
4713 The following example shows that this even allows
4714 mutually recursive postconditions as in:
4715
4716
4717 .. code-block:: ada
4718
4719 package Parity_Functions is
4720 function Odd (X : Natural) return Boolean;
4721 pragma Postcondition
4722 (Odd'Result =
4723 (x = 1
4724 or else
4725 (x /= 0 and then Even (X - 1))));
4726
4727 function Even (X : Natural) return Boolean;
4728 pragma Postcondition
4729 (Even'Result =
4730 (x = 0
4731 or else
4732 (x /= 1 and then Odd (X - 1))));
4733
4734 end Parity_Functions;
4735
4736
4737 There are no restrictions on the complexity or form of
4738 conditions used within ``Postcondition`` pragmas.
4739 The following example shows that it is even possible
4740 to verify performance behavior.
4741
4742
4743 .. code-block:: ada
4744
4745 package Sort is
4746
4747 Performance : constant Float;
4748 -- Performance constant set by implementation
4749 -- to match target architecture behavior.
4750
4751 procedure Treesort (Arg : String);
4752 -- Sorts characters of argument using N*logN sort
4753 pragma Postcondition
4754 (Float (Clock - Clock'Old) <=
4755 Float (Arg'Length) *
4756 log (Float (Arg'Length)) *
4757 Performance);
4758 end Sort;
4759
4760
4761 Note: postcondition pragmas associated with subprograms that are
4762 marked as Inline_Always, or those marked as Inline with front-end
4763 inlining (-gnatN option set) are accepted and legality-checked
4764 by the compiler, but are ignored at run-time even if postcondition
4765 checking is enabled.
4766
4767 Note that pragma ``Postcondition`` differs from the language-defined
4768 ``Post`` aspect (and corresponding ``Post`` pragma) in allowing
4769 multiple occurrences, allowing occurences in the body even if there
4770 is a separate spec, and allowing a second string parameter, and the
4771 use of the pragma identifier ``Check``. Historically, pragma
4772 ``Postcondition`` was implemented prior to the development of
4773 Ada 2012, and has been retained in its original form for
4774 compatibility purposes.
4775
4776 Pragma Post_Class
4777 =================
4778 .. index:: Post
4779
4780 .. index:: Checks, postconditions
4781
4782
4783 Syntax:
4784
4785
4786 .. code-block:: ada
4787
4788 pragma Post_Class (Boolean_Expression);
4789
4790
4791 The ``Post_Class`` pragma is intended to be an exact replacement for
4792 the language-defined
4793 ``Post'Class`` aspect, and shares its restrictions and semantics.
4794 It must appear either immediately following the corresponding
4795 subprogram declaration (only other pragmas may intervene), or
4796 if there is no separate subprogram declaration, then it can
4797 appear at the start of the declarations in a subprogram body
4798 (preceded only by other pragmas).
4799
4800 Note: This pragma is called ``Post_Class`` rather than
4801 ``Post'Class`` because the latter would not be strictly
4802 conforming to the allowed syntax for pragmas. The motivation
4803 for providing pragmas equivalent to the aspects is to allow a program
4804 to be written using the pragmas, and then compiled if necessary
4805 using an Ada compiler that does not recognize the pragmas or
4806 aspects, but is prepared to ignore the pragmas. The assertion
4807 policy that controls this pragma is ``Post'Class``, not
4808 ``Post_Class``.
4809
4810 Pragma Pre
4811 ==========
4812 .. index:: Pre
4813
4814 .. index:: Checks, preconditions
4815
4816
4817 Syntax:
4818
4819
4820 .. code-block:: ada
4821
4822 pragma Pre (Boolean_Expression);
4823
4824
4825 The ``Pre`` pragma is intended to be an exact replacement for
4826 the language-defined
4827 ``Pre`` aspect, and shares its restrictions and semantics.
4828 It must appear either immediately following the corresponding
4829 subprogram declaration (only other pragmas may intervene), or
4830 if there is no separate subprogram declaration, then it can
4831 appear at the start of the declarations in a subprogram body
4832 (preceded only by other pragmas).
4833
4834 Pragma Precondition
4835 ===================
4836 .. index:: Preconditions
4837
4838 .. index:: Checks, preconditions
4839
4840
4841 Syntax:
4842
4843
4844 ::
4845
4846 pragma Precondition (
4847 [Check =>] Boolean_Expression
4848 [,[Message =>] String_Expression]);
4849
4850
4851 The ``Precondition`` pragma is similar to ``Postcondition``
4852 except that the corresponding checks take place immediately upon
4853 entry to the subprogram, and if a precondition fails, the exception
4854 is raised in the context of the caller, and the attribute 'Result
4855 cannot be used within the precondition expression.
4856
4857 Otherwise, the placement and visibility rules are identical to those
4858 described for postconditions. The following is an example of use
4859 within a package spec:
4860
4861
4862 .. code-block:: ada
4863
4864 package Math_Functions is
4865 ...
4866 function Sqrt (Arg : Float) return Float;
4867 pragma Precondition (Arg >= 0.0)
4868 ...
4869 end Math_Functions;
4870
4871
4872 ``Precondition`` pragmas may appear either immediately following the
4873 (separate) declaration of a subprogram, or at the start of the
4874 declarations of a subprogram body. Only other pragmas may intervene
4875 (that is appear between the subprogram declaration and its
4876 postconditions, or appear before the postcondition in the
4877 declaration sequence in a subprogram body).
4878
4879 Note: precondition pragmas associated with subprograms that are
4880 marked as Inline_Always, or those marked as Inline with front-end
4881 inlining (-gnatN option set) are accepted and legality-checked
4882 by the compiler, but are ignored at run-time even if precondition
4883 checking is enabled.
4884
4885 Note that pragma ``Precondition`` differs from the language-defined
4886 ``Pre`` aspect (and corresponding ``Pre`` pragma) in allowing
4887 multiple occurrences, allowing occurences in the body even if there
4888 is a separate spec, and allowing a second string parameter, and the
4889 use of the pragma identifier ``Check``. Historically, pragma
4890 ``Precondition`` was implemented prior to the development of
4891 Ada 2012, and has been retained in its original form for
4892 compatibility purposes.
4893
4894 .. _Pragma-Predicate:
4895
4896 Pragma Predicate
4897 ================
4898
4899 Syntax:
4900
4901
4902 ::
4903
4904 pragma Predicate
4905 ([Entity =>] type_LOCAL_NAME,
4906 [Check =>] EXPRESSION);
4907
4908
4909 This pragma (available in all versions of Ada in GNAT) encompasses both
4910 the ``Static_Predicate`` and ``Dynamic_Predicate`` aspects in
4911 Ada 2012. A predicate is regarded as static if it has an allowed form
4912 for ``Static_Predicate`` and is otherwise treated as a
4913 ``Dynamic_Predicate``. Otherwise, predicates specified by this
4914 pragma behave exactly as described in the Ada 2012 reference manual.
4915 For example, if we have
4916
4917
4918 .. code-block:: ada
4919
4920 type R is range 1 .. 10;
4921 subtype S is R;
4922 pragma Predicate (Entity => S, Check => S not in 4 .. 6);
4923 subtype Q is R
4924 pragma Predicate (Entity => Q, Check => F(Q) or G(Q));
4925
4926
4927 the effect is identical to the following Ada 2012 code:
4928
4929
4930 .. code-block:: ada
4931
4932 type R is range 1 .. 10;
4933 subtype S is R with
4934 Static_Predicate => S not in 4 .. 6;
4935 subtype Q is R with
4936 Dynamic_Predicate => F(Q) or G(Q);
4937
4938
4939 Note that there are no pragmas ``Dynamic_Predicate``
4940 or ``Static_Predicate``. That is
4941 because these pragmas would affect legality and semantics of
4942 the program and thus do not have a neutral effect if ignored.
4943 The motivation behind providing pragmas equivalent to
4944 corresponding aspects is to allow a program to be written
4945 using the pragmas, and then compiled with a compiler that
4946 will ignore the pragmas. That doesn't work in the case of
4947 static and dynamic predicates, since if the corresponding
4948 pragmas are ignored, then the behavior of the program is
4949 fundamentally changed (for example a membership test
4950 ``A in B`` would not take into account a predicate
4951 defined for subtype B). When following this approach, the
4952 use of predicates should be avoided.
4953
4954 Pragma Predicate_Failure
4955 ========================
4956
4957 Syntax:
4958
4959
4960 ::
4961
4962 pragma Predicate_Failure
4963 ([Entity =>] type_LOCAL_NAME,
4964 [Message =>] String_Expression);
4965
4966
4967 The ``Predicate_Failure`` pragma is intended to be an exact replacement for
4968 the language-defined
4969 ``Predicate_Failure`` aspect, and shares its restrictions and semantics.
4970
4971 Pragma Preelaborable_Initialization
4972 ===================================
4973
4974 Syntax:
4975
4976
4977 .. code-block:: ada
4978
4979 pragma Preelaborable_Initialization (DIRECT_NAME);
4980
4981
4982 This pragma is standard in Ada 2005, but is available in all earlier
4983 versions of Ada as an implementation-defined pragma.
4984 See Ada 2012 Reference Manual for details.
4985
4986 Pragma Prefix_Exception_Messages
4987 ================================
4988 .. index:: Prefix_Exception_Messages
4989
4990 .. index:: exception
4991
4992 .. index:: Exception_Message
4993
4994
4995 Syntax:
4996
4997
4998 .. code-block:: ada
4999
5000 pragma Prefix_Exception_Messages;
5001
5002
5003 This is an implementation-defined configuration pragma that affects the
5004 behavior of raise statements with a message given as a static string
5005 constant (typically a string literal). In such cases, the string will
5006 be automatically prefixed by the name of the enclosing entity (giving
5007 the package and subprogram containing the raise statement). This helps
5008 to identify where messages are coming from, and this mode is automatic
5009 for the run-time library.
5010
5011 The pragma has no effect if the message is computed with an expression other
5012 than a static string constant, since the assumption in this case is that
5013 the program computes exactly the string it wants. If you still want the
5014 prefixing in this case, you can always call
5015 ``GNAT.Source_Info.Enclosing_Entity`` and prepend the string manually.
5016
5017 Pragma Pre_Class
5018 ================
5019 .. index:: Pre_Class
5020
5021 .. index:: Checks, preconditions
5022
5023
5024 Syntax:
5025
5026
5027 .. code-block:: ada
5028
5029 pragma Pre_Class (Boolean_Expression);
5030
5031
5032 The ``Pre_Class`` pragma is intended to be an exact replacement for
5033 the language-defined
5034 ``Pre'Class`` aspect, and shares its restrictions and semantics.
5035 It must appear either immediately following the corresponding
5036 subprogram declaration (only other pragmas may intervene), or
5037 if there is no separate subprogram declaration, then it can
5038 appear at the start of the declarations in a subprogram body
5039 (preceded only by other pragmas).
5040
5041 Note: This pragma is called ``Pre_Class`` rather than
5042 ``Pre'Class`` because the latter would not be strictly
5043 conforming to the allowed syntax for pragmas. The motivation
5044 for providing pragmas equivalent to the aspects is to allow a program
5045 to be written using the pragmas, and then compiled if necessary
5046 using an Ada compiler that does not recognize the pragmas or
5047 aspects, but is prepared to ignore the pragmas. The assertion
5048 policy that controls this pragma is ``Pre'Class``, not
5049 ``Pre_Class``.
5050
5051 Pragma Priority_Specific_Dispatching
5052 ====================================
5053
5054 Syntax:
5055
5056
5057 ::
5058
5059 pragma Priority_Specific_Dispatching (
5060 POLICY_IDENTIFIER,
5061 first_priority_EXPRESSION,
5062 last_priority_EXPRESSION)
5063
5064 POLICY_IDENTIFIER ::=
5065 EDF_Across_Priorities |
5066 FIFO_Within_Priorities |
5067 Non_Preemptive_Within_Priorities |
5068 Round_Robin_Within_Priorities
5069
5070
5071 This pragma is standard in Ada 2005, but is available in all earlier
5072 versions of Ada as an implementation-defined pragma.
5073 See Ada 2012 Reference Manual for details.
5074
5075 Pragma Profile
5076 ==============
5077
5078 Syntax:
5079
5080
5081 .. code-block:: ada
5082
5083 pragma Profile (Ravenscar | Restricted | Rational | Jorvik |
5084 GNAT_Extended_Ravenscar | GNAT_Ravenscar_EDF );
5085
5086
5087 This pragma is standard in Ada 2005, but is available in all earlier
5088 versions of Ada as an implementation-defined pragma. This is a
5089 configuration pragma that establishes a set of configuration pragmas
5090 that depend on the argument. ``Ravenscar`` is standard in Ada 2005.
5091 ``Jorvik`` is standard in Ada 202x.
5092 The other possibilities (``Restricted``, ``Rational``,
5093 ``GNAT_Extended_Ravenscar``, ``GNAT_Ravenscar_EDF``)
5094 are implementation-defined. ``GNAT_Extended_Ravenscar`` is an alias for ``Jorvik``.
5095
5096 The set of configuration pragmas is defined in the following sections.
5097
5098
5099 * Pragma Profile (Ravenscar)
5100
5101 The ``Ravenscar`` profile is standard in Ada 2005,
5102 but is available in all earlier
5103 versions of Ada as an implementation-defined pragma. This profile
5104 establishes the following set of configuration pragmas:
5105
5106 * ``Task_Dispatching_Policy (FIFO_Within_Priorities)``
5107
5108 [RM D.2.2] Tasks are dispatched following a preemptive
5109 priority-ordered scheduling policy.
5110
5111
5112 * ``Locking_Policy (Ceiling_Locking)``
5113
5114 [RM D.3] While tasks and interrupts execute a protected action, they inherit
5115 the ceiling priority of the corresponding protected object.
5116
5117
5118 * ``Detect_Blocking``
5119
5120 This pragma forces the detection of potentially blocking operations within a
5121 protected operation, and to raise Program_Error if that happens.
5122
5123 plus the following set of restrictions:
5124
5125 * ``Max_Entry_Queue_Length => 1``
5126
5127 No task can be queued on a protected entry.
5128
5129 * ``Max_Protected_Entries => 1``
5130
5131 * ``Max_Task_Entries => 0``
5132
5133 No rendezvous statements are allowed.
5134
5135 * ``No_Abort_Statements``
5136
5137 * ``No_Dynamic_Attachment``
5138
5139 * ``No_Dynamic_Priorities``
5140
5141 * ``No_Implicit_Heap_Allocations``
5142
5143 * ``No_Local_Protected_Objects``
5144
5145 * ``No_Local_Timing_Events``
5146
5147 * ``No_Protected_Type_Allocators``
5148
5149 * ``No_Relative_Delay``
5150
5151 * ``No_Requeue_Statements``
5152
5153 * ``No_Select_Statements``
5154
5155 * ``No_Specific_Termination_Handlers``
5156
5157 * ``No_Task_Allocators``
5158
5159 * ``No_Task_Hierarchy``
5160
5161 * ``No_Task_Termination``
5162
5163 * ``Simple_Barriers``
5164
5165 The Ravenscar profile also includes the following restrictions that specify
5166 that there are no semantic dependencies on the corresponding predefined
5167 packages:
5168
5169 * ``No_Dependence => Ada.Asynchronous_Task_Control``
5170
5171 * ``No_Dependence => Ada.Calendar``
5172
5173 * ``No_Dependence => Ada.Execution_Time.Group_Budget``
5174
5175 * ``No_Dependence => Ada.Execution_Time.Timers``
5176
5177 * ``No_Dependence => Ada.Task_Attributes``
5178
5179 * ``No_Dependence => System.Multiprocessors.Dispatching_Domains``
5180
5181 This set of configuration pragmas and restrictions correspond to the
5182 definition of the 'Ravenscar Profile' for limited tasking, devised and
5183 published by the :title:`International Real-Time Ada Workshop, 1997`.
5184 A description is also available at
5185 `http://www-users.cs.york.ac.uk/~burns/ravenscar.ps <http://www-users.cs.york.ac.uk/~burns/ravenscar.ps>`_.
5186
5187 The original definition of the profile was revised at subsequent IRTAW
5188 meetings. It has been included in the ISO
5189 :title:`Guide for the Use of the Ada Programming Language in High Integrity Systems`,
5190 and was made part of the Ada 2005 standard.
5191 The formal definition given by
5192 the Ada Rapporteur Group (ARG) can be found in two Ada Issues (AI-249 and
5193 AI-305) available at
5194 `http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00249.txt <http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00249.txt>`_ and
5195 `http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00305.txt <http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00305.txt>`_.
5196
5197 The above set is a superset of the restrictions provided by pragma
5198 ``Profile (Restricted)``, it includes six additional restrictions
5199 (``Simple_Barriers``, ``No_Select_Statements``,
5200 ``No_Calendar``, ``No_Implicit_Heap_Allocations``,
5201 ``No_Relative_Delay`` and ``No_Task_Termination``). This means
5202 that pragma ``Profile (Ravenscar)``, like the pragma
5203 ``Profile (Restricted)``,
5204 automatically causes the use of a simplified,
5205 more efficient version of the tasking run-time library.
5206
5207 * Pragma Profile (Jorvik)
5208
5209 ``Jorvik`` is the new profile added to the Ada 202x draft standard,
5210 previously implemented under the name ``GNAT_Extended_Ravenscar``.
5211
5212 The ``No_Implicit_Heap_Allocations`` restriction has been replaced
5213 by ``No_Implicit_Task_Allocations`` and
5214 ``No_Implicit_Protected_Object_Allocations``.
5215
5216 The ``Simple_Barriers`` restriction has been replaced by
5217 ``Pure_Barriers``.
5218
5219 The ``Max_Protected_Entries``, ``Max_Entry_Queue_Length``, and
5220 ``No_Relative_Delay`` restrictions have been removed.
5221
5222 Details on the rationale for ``Jorvik`` and implications for use may be
5223 found in :title:`A New Ravenscar-Based Profile` by P. Rogers, J. Ruiz,
5224 T. Gingold and P. Bernardi, in :title:`Reliable Software Technologies --
5225 Ada Europe 2017`, Springer-Verlag Lecture Notes in Computer Science,
5226 Number 10300.
5227
5228
5229 * Pragma Profile (GNAT_Ravenscar_EDF)
5230
5231 This profile corresponds to the Ravenscar profile but using
5232 EDF_Across_Priority as the Task_Scheduling_Policy.
5233
5234 * Pragma Profile (Restricted)
5235
5236 This profile corresponds to the GNAT restricted run time. It
5237 establishes the following set of restrictions:
5238
5239 * ``No_Abort_Statements``
5240 * ``No_Entry_Queue``
5241 * ``No_Task_Hierarchy``
5242 * ``No_Task_Allocators``
5243 * ``No_Dynamic_Priorities``
5244 * ``No_Terminate_Alternatives``
5245 * ``No_Dynamic_Attachment``
5246 * ``No_Protected_Type_Allocators``
5247 * ``No_Local_Protected_Objects``
5248 * ``No_Requeue_Statements``
5249 * ``No_Task_Attributes_Package``
5250 * ``Max_Asynchronous_Select_Nesting = 0``
5251 * ``Max_Task_Entries = 0``
5252 * ``Max_Protected_Entries = 1``
5253 * ``Max_Select_Alternatives = 0``
5254
5255 This set of restrictions causes the automatic selection of a simplified
5256 version of the run time that provides improved performance for the
5257 limited set of tasking functionality permitted by this set of restrictions.
5258
5259 * Pragma Profile (Rational)
5260
5261 The Rational profile is intended to facilitate porting legacy code that
5262 compiles with the Rational APEX compiler, even when the code includes non-
5263 conforming Ada constructs. The profile enables the following three pragmas:
5264
5265 * ``pragma Implicit_Packing``
5266 * ``pragma Overriding_Renamings``
5267 * ``pragma Use_VADS_Size``
5268
5269
5270 Pragma Profile_Warnings
5271 =======================
5272
5273 Syntax:
5274
5275
5276 .. code-block:: ada
5277
5278 pragma Profile_Warnings (Ravenscar | Restricted | Rational);
5279
5280
5281 This is an implementation-defined pragma that is similar in
5282 effect to ``pragma Profile`` except that instead of
5283 generating ``Restrictions`` pragmas, it generates
5284 ``Restriction_Warnings`` pragmas. The result is that
5285 violations of the profile generate warning messages instead
5286 of error messages.
5287
5288 Pragma Propagate_Exceptions
5289 ===========================
5290 .. index:: Interfacing to C++
5291
5292
5293 Syntax:
5294
5295
5296 .. code-block:: ada
5297
5298 pragma Propagate_Exceptions;
5299
5300
5301 This pragma is now obsolete and, other than generating a warning if warnings
5302 on obsolescent features are enabled, is ignored.
5303 It is retained for compatibility
5304 purposes. It used to be used in connection with optimization of
5305 a now-obsolete mechanism for implementation of exceptions.
5306
5307 Pragma Provide_Shift_Operators
5308 ==============================
5309 .. index:: Shift operators
5310
5311
5312 Syntax:
5313
5314
5315 .. code-block:: ada
5316
5317 pragma Provide_Shift_Operators (integer_first_subtype_LOCAL_NAME);
5318
5319
5320 This pragma can be applied to a first subtype local name that specifies
5321 either an unsigned or signed type. It has the effect of providing the
5322 five shift operators (Shift_Left, Shift_Right, Shift_Right_Arithmetic,
5323 Rotate_Left and Rotate_Right) for the given type. It is similar to
5324 including the function declarations for these five operators, together
5325 with the pragma Import (Intrinsic, ...) statements.
5326
5327 Pragma Psect_Object
5328 ===================
5329
5330 Syntax:
5331
5332
5333 ::
5334
5335 pragma Psect_Object (
5336 [Internal =>] LOCAL_NAME,
5337 [, [External =>] EXTERNAL_SYMBOL]
5338 [, [Size =>] EXTERNAL_SYMBOL]);
5339
5340 EXTERNAL_SYMBOL ::=
5341 IDENTIFIER
5342 | static_string_EXPRESSION
5343
5344
5345 This pragma is identical in effect to pragma ``Common_Object``.
5346
5347 .. _Pragma-Pure_Function:
5348
5349 Pragma Pure_Function
5350 ====================
5351
5352 Syntax:
5353
5354
5355 ::
5356
5357 pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
5358
5359
5360 This pragma appears in the same declarative part as a function
5361 declaration (or a set of function declarations if more than one
5362 overloaded declaration exists, in which case the pragma applies
5363 to all entities). It specifies that the function ``Entity`` is
5364 to be considered pure for the purposes of code generation. This means
5365 that the compiler can assume that there are no side effects, and
5366 in particular that two identical calls produce the same result in
5367 the same context. It also means that the function can be used in
5368 an address clause.
5369
5370 Note that, quite deliberately, there are no static checks to try
5371 to ensure that this promise is met, so ``Pure_Function`` can be used
5372 with functions that are conceptually pure, even if they do modify
5373 global variables. For example, a square root function that is
5374 instrumented to count the number of times it is called is still
5375 conceptually pure, and can still be optimized, even though it
5376 modifies a global variable (the count). Memo functions are another
5377 example (where a table of previous calls is kept and consulted to
5378 avoid re-computation).
5379
5380 Note also that the normal rules excluding optimization of subprograms
5381 in pure units (when parameter types are descended from System.Address,
5382 or when the full view of a parameter type is limited), do not apply
5383 for the Pure_Function case. If you explicitly specify Pure_Function,
5384 the compiler may optimize away calls with identical arguments, and
5385 if that results in unexpected behavior, the proper action is not to
5386 use the pragma for subprograms that are not (conceptually) pure.
5387
5388 Note: Most functions in a ``Pure`` package are automatically pure, and
5389 there is no need to use pragma ``Pure_Function`` for such functions. One
5390 exception is any function that has at least one formal of type
5391 ``System.Address`` or a type derived from it. Such functions are not
5392 considered pure by default, since the compiler assumes that the
5393 ``Address`` parameter may be functioning as a pointer and that the
5394 referenced data may change even if the address value does not.
5395 Similarly, imported functions are not considered to be pure by default,
5396 since there is no way of checking that they are in fact pure. The use
5397 of pragma ``Pure_Function`` for such a function will override these default
5398 assumption, and cause the compiler to treat a designated subprogram as pure
5399 in these cases.
5400
5401 Note: If pragma ``Pure_Function`` is applied to a renamed function, it
5402 applies to the underlying renamed function. This can be used to
5403 disambiguate cases of overloading where some but not all functions
5404 in a set of overloaded functions are to be designated as pure.
5405
5406 If pragma ``Pure_Function`` is applied to a library-level function, the
5407 function is also considered pure from an optimization point of view, but the
5408 unit is not a Pure unit in the categorization sense. So for example, a function
5409 thus marked is free to ``with`` non-pure units.
5410
5411 Pragma Rational
5412 ===============
5413
5414 Syntax:
5415
5416
5417 .. code-block:: ada
5418
5419 pragma Rational;
5420
5421
5422 This pragma is considered obsolescent, but is retained for
5423 compatibility purposes. It is equivalent to:
5424
5425
5426 .. code-block:: ada
5427
5428 pragma Profile (Rational);
5429
5430
5431 Pragma Ravenscar
5432 ================
5433
5434 Syntax:
5435
5436
5437 .. code-block:: ada
5438
5439 pragma Ravenscar;
5440
5441
5442 This pragma is considered obsolescent, but is retained for
5443 compatibility purposes. It is equivalent to:
5444
5445
5446 .. code-block:: ada
5447
5448 pragma Profile (Ravenscar);
5449
5450
5451 which is the preferred method of setting the ``Ravenscar`` profile.
5452
5453 .. _Pragma-Refined_Depends:
5454
5455 Pragma Refined_Depends
5456 ======================
5457
5458 Syntax:
5459
5460 .. code-block:: ada
5461
5462 pragma Refined_Depends (DEPENDENCY_RELATION);
5463
5464 DEPENDENCY_RELATION ::=
5465 null
5466 | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
5467
5468 DEPENDENCY_CLAUSE ::=
5469 OUTPUT_LIST =>[+] INPUT_LIST
5470 | NULL_DEPENDENCY_CLAUSE
5471
5472 NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
5473
5474 OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
5475
5476 INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
5477
5478 OUTPUT ::= NAME | FUNCTION_RESULT
5479 INPUT ::= NAME
5480
5481 where FUNCTION_RESULT is a function Result attribute_reference
5482
5483 For the semantics of this pragma, see the entry for aspect ``Refined_Depends`` in
5484 the SPARK 2014 Reference Manual, section 6.1.5.
5485
5486 .. _Pragma-Refined_Global:
5487
5488 Pragma Refined_Global
5489 =====================
5490
5491 Syntax:
5492
5493 .. code-block:: ada
5494
5495 pragma Refined_Global (GLOBAL_SPECIFICATION);
5496
5497 GLOBAL_SPECIFICATION ::=
5498 null
5499 | (GLOBAL_LIST)
5500 | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
5501
5502 MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
5503
5504 MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
5505 GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
5506 GLOBAL_ITEM ::= NAME
5507
5508 For the semantics of this pragma, see the entry for aspect ``Refined_Global`` in
5509 the SPARK 2014 Reference Manual, section 6.1.4.
5510
5511 .. _Pragma-Refined_Post:
5512
5513 Pragma Refined_Post
5514 ===================
5515
5516 Syntax:
5517
5518 .. code-block:: ada
5519
5520 pragma Refined_Post (boolean_EXPRESSION);
5521
5522 For the semantics of this pragma, see the entry for aspect ``Refined_Post`` in
5523 the SPARK 2014 Reference Manual, section 7.2.7.
5524
5525 .. _Pragma-Refined_State:
5526
5527 Pragma Refined_State
5528 ====================
5529
5530 Syntax:
5531
5532 .. code-block:: ada
5533
5534 pragma Refined_State (REFINEMENT_LIST);
5535
5536 REFINEMENT_LIST ::=
5537 (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
5538
5539 REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
5540
5541 CONSTITUENT_LIST ::=
5542 null
5543 | CONSTITUENT
5544 | (CONSTITUENT {, CONSTITUENT})
5545
5546 CONSTITUENT ::= object_NAME | state_NAME
5547
5548 For the semantics of this pragma, see the entry for aspect ``Refined_State`` in
5549 the SPARK 2014 Reference Manual, section 7.2.2.
5550
5551 Pragma Relative_Deadline
5552 ========================
5553
5554 Syntax:
5555
5556
5557 .. code-block:: ada
5558
5559 pragma Relative_Deadline (time_span_EXPRESSION);
5560
5561
5562 This pragma is standard in Ada 2005, but is available in all earlier
5563 versions of Ada as an implementation-defined pragma.
5564 See Ada 2012 Reference Manual for details.
5565
5566 .. _Pragma-Remote_Access_Type:
5567
5568 Pragma Remote_Access_Type
5569 =========================
5570
5571 Syntax:
5572
5573
5574 ::
5575
5576 pragma Remote_Access_Type ([Entity =>] formal_access_type_LOCAL_NAME);
5577
5578
5579 This pragma appears in the formal part of a generic declaration.
5580 It specifies an exception to the RM rule from E.2.2(17/2), which forbids
5581 the use of a remote access to class-wide type as actual for a formal
5582 access type.
5583
5584 When this pragma applies to a formal access type ``Entity``, that
5585 type is treated as a remote access to class-wide type in the generic.
5586 It must be a formal general access type, and its designated type must
5587 be the class-wide type of a formal tagged limited private type from the
5588 same generic declaration.
5589
5590 In the generic unit, the formal type is subject to all restrictions
5591 pertaining to remote access to class-wide types. At instantiation, the
5592 actual type must be a remote access to class-wide type.
5593
5594 Pragma Rename_Pragma
5595 ============================
5596 .. index:: Pragmas, synonyms
5597
5598 Syntax:
5599
5600
5601 ::
5602
5603 pragma Rename_Pragma (
5604 [New_Name =>] IDENTIFIER,
5605 [Renamed =>] pragma_IDENTIFIER);
5606
5607 This pragma provides a mechanism for supplying new names for existing
5608 pragmas. The ``New_Name`` identifier can subsequently be used as a synonym for
5609 the Renamed pragma. For example, suppose you have code that was originally
5610 developed on a compiler that supports Inline_Only as an implementation defined
5611 pragma. And suppose the semantics of pragma Inline_Only are identical to (or at
5612 least very similar to) the GNAT implementation defined pragma
5613 Inline_Always. You could globally replace Inline_Only with Inline_Always.
5614
5615 However, to avoid that source modification, you could instead add a
5616 configuration pragma:
5617
5618 .. code-block:: ada
5619
5620 pragma Rename_Pragma (
5621 New_Name => Inline_Only,
5622 Renamed => Inline_Always);
5623
5624
5625 Then GNAT will treat "pragma Inline_Only ..." as if you had written
5626 "pragma Inline_Always ...".
5627
5628 Pragma Inline_Only will not necessarily mean the same thing as the other Ada
5629 compiler; it's up to you to make sure the semantics are close enough.
5630
5631 Pragma Restricted_Run_Time
5632 ==========================
5633
5634 Syntax:
5635
5636
5637 .. code-block:: ada
5638
5639 pragma Restricted_Run_Time;
5640
5641
5642 This pragma is considered obsolescent, but is retained for
5643 compatibility purposes. It is equivalent to:
5644
5645
5646 .. code-block:: ada
5647
5648 pragma Profile (Restricted);
5649
5650
5651 which is the preferred method of setting the restricted run time
5652 profile.
5653
5654 Pragma Restriction_Warnings
5655 ===========================
5656
5657 Syntax:
5658
5659
5660 ::
5661
5662 pragma Restriction_Warnings
5663 (restriction_IDENTIFIER {, restriction_IDENTIFIER});
5664
5665
5666 This pragma allows a series of restriction identifiers to be
5667 specified (the list of allowed identifiers is the same as for
5668 pragma ``Restrictions``). For each of these identifiers
5669 the compiler checks for violations of the restriction, but
5670 generates a warning message rather than an error message
5671 if the restriction is violated.
5672
5673 One use of this is in situations where you want to know
5674 about violations of a restriction, but you want to ignore some of
5675 these violations. Consider this example, where you want to set
5676 Ada_95 mode and enable style checks, but you want to know about
5677 any other use of implementation pragmas:
5678
5679
5680 .. code-block:: ada
5681
5682 pragma Restriction_Warnings (No_Implementation_Pragmas);
5683 pragma Warnings (Off, "violation of No_Implementation_Pragmas");
5684 pragma Ada_95;
5685 pragma Style_Checks ("2bfhkM160");
5686 pragma Warnings (On, "violation of No_Implementation_Pragmas");
5687
5688
5689 By including the above lines in a configuration pragmas file,
5690 the Ada_95 and Style_Checks pragmas are accepted without
5691 generating a warning, but any other use of implementation
5692 defined pragmas will cause a warning to be generated.
5693
5694 Pragma Reviewable
5695 =================
5696
5697 Syntax:
5698
5699
5700 .. code-block:: ada
5701
5702 pragma Reviewable;
5703
5704
5705 This pragma is an RM-defined standard pragma, but has no effect on the
5706 program being compiled, or on the code generated for the program.
5707
5708 To obtain the required output specified in RM H.3.1, the compiler must be
5709 run with various special switches as follows:
5710
5711 * *Where compiler-generated run-time checks remain*
5712
5713 The switch *-gnatGL*
5714 may be used to list the expanded code in pseudo-Ada form.
5715 Runtime checks show up in the listing either as explicit
5716 checks or operators marked with {} to indicate a check is present.
5717
5718
5719 * *An identification of known exceptions at compile time*
5720
5721 If the program is compiled with *-gnatwa*,
5722 the compiler warning messages will indicate all cases where the compiler
5723 detects that an exception is certain to occur at run time.
5724
5725
5726 * *Possible reads of uninitialized variables*
5727
5728 The compiler warns of many such cases, but its output is incomplete.
5729
5730 .. only:: PRO or GPL
5731
5732 The CodePeer analysis tool
5733 may be used to obtain a comprehensive list of all
5734 possible points at which uninitialized data may be read.
5735
5736 .. only:: FSF
5737
5738 A supplemental static analysis tool
5739 may be used to obtain a comprehensive list of all
5740 possible points at which uninitialized data may be read.
5741
5742
5743 * *Where run-time support routines are implicitly invoked*
5744
5745 In the output from *-gnatGL*,
5746 run-time calls are explicitly listed as calls to the relevant
5747 run-time routine.
5748
5749
5750 * *Object code listing*
5751
5752 This may be obtained either by using the *-S* switch,
5753 or the objdump utility.
5754
5755
5756 * *Constructs known to be erroneous at compile time*
5757
5758 These are identified by warnings issued by the compiler (use *-gnatwa*).
5759
5760
5761 * *Stack usage information*
5762
5763 Static stack usage data (maximum per-subprogram) can be obtained via the
5764 *-fstack-usage* switch to the compiler.
5765 Dynamic stack usage data (per task) can be obtained via the *-u* switch
5766 to gnatbind
5767
5768 .. only:: PRO or GPL
5769
5770 The gnatstack utility
5771 can be used to provide additional information on stack usage.
5772
5773
5774 * *Object code listing of entire partition*
5775
5776 This can be obtained by compiling the partition with *-S*,
5777 or by applying objdump
5778 to all the object files that are part of the partition.
5779
5780
5781 * *A description of the run-time model*
5782
5783 The full sources of the run-time are available, and the documentation of
5784 these routines describes how these run-time routines interface to the
5785 underlying operating system facilities.
5786
5787
5788 * *Control and data-flow information*
5789
5790 .. only:: PRO or GPL
5791
5792 The CodePeer tool
5793 may be used to obtain complete control and data-flow information, as well as
5794 comprehensive messages identifying possible problems based on this
5795 information.
5796
5797 .. only:: FSF
5798
5799 A supplemental static analysis tool
5800 may be used to obtain complete control and data-flow information, as well as
5801 comprehensive messages identifying possible problems based on this
5802 information.
5803
5804 .. _Pragma-Secondary_Stack_Size:
5805
5806 Pragma Secondary_Stack_Size
5807 ===========================
5808
5809 Syntax:
5810
5811 .. code-block:: ada
5812
5813 pragma Secondary_Stack_Size (integer_EXPRESSION);
5814
5815 This pragma appears within the task definition of a single task declaration
5816 or a task type declaration (like pragma ``Storage_Size``) and applies to all
5817 task objects of that type. The argument specifies the size of the secondary
5818 stack to be used by these task objects, and must be of an integer type. The
5819 secondary stack is used to handle functions that return a variable-sized
5820 result, for example a function returning an unconstrained String.
5821
5822 Note this pragma only applies to targets using fixed secondary stacks, like
5823 VxWorks 653 and bare board targets, where a fixed block for the
5824 secondary stack is allocated from the primary stack of the task. By default,
5825 these targets assign a percentage of the primary stack for the secondary stack,
5826 as defined by ``System.Parameter.Sec_Stack_Percentage``. With this pragma,
5827 an ``integer_EXPRESSION`` of bytes is assigned from the primary stack instead.
5828
5829 For most targets, the pragma does not apply as the secondary stack grows on
5830 demand: allocated as a chain of blocks in the heap. The default size of these
5831 blocks can be modified via the :switch:`-D` binder option as described in
5832 :title:`GNAT User's Guide`.
5833
5834 Note that no check is made to see if the secondary stack can fit inside the
5835 primary stack.
5836
5837 Note the pragma cannot appear when the restriction ``No_Secondary_Stack``
5838 is in effect.
5839
5840 Pragma Share_Generic
5841 ====================
5842
5843 Syntax:
5844
5845
5846 ::
5847
5848 pragma Share_Generic (GNAME {, GNAME});
5849
5850 GNAME ::= generic_unit_NAME | generic_instance_NAME
5851
5852
5853 This pragma is provided for compatibility with Dec Ada 83. It has
5854 no effect in GNAT (which does not implement shared generics), other
5855 than to check that the given names are all names of generic units or
5856 generic instances.
5857
5858 .. _Pragma-Shared:
5859
5860 Pragma Shared
5861 =============
5862
5863 This pragma is provided for compatibility with Ada 83. The syntax and
5864 semantics are identical to pragma Atomic.
5865
5866 Pragma Short_Circuit_And_Or
5867 ===========================
5868
5869 Syntax:
5870
5871
5872 .. code-block:: ada
5873
5874 pragma Short_Circuit_And_Or;
5875
5876
5877 This configuration pragma causes any occurrence of the AND operator applied to
5878 operands of type Standard.Boolean to be short-circuited (i.e. the AND operator
5879 is treated as if it were AND THEN). Or is similarly treated as OR ELSE. This
5880 may be useful in the context of certification protocols requiring the use of
5881 short-circuited logical operators. If this configuration pragma occurs locally
5882 within the file being compiled, it applies only to the file being compiled.
5883 There is no requirement that all units in a partition use this option.
5884
5885 Pragma Short_Descriptors
5886 ========================
5887
5888 Syntax:
5889
5890
5891 .. code-block:: ada
5892
5893 pragma Short_Descriptors;
5894
5895
5896 This pragma is provided for compatibility with other Ada implementations. It
5897 is recognized but ignored by all current versions of GNAT.
5898
5899 .. _Pragma-Side_Effects:
5900
5901 Pragma Side_Effects
5902 ===================
5903
5904 Syntax:
5905
5906 .. code-block:: ada
5907
5908 pragma Side_Effects [ (static_boolean_EXPRESSION) ];
5909
5910 For the semantics of this pragma, see the entry for aspect
5911 ``Side_Effects`` in the SPARK Reference Manual, section 6.1.12.
5912
5913 .. _Pragma-Simple_Storage_Pool_Type:
5914
5915 Pragma Simple_Storage_Pool_Type
5916 ===============================
5917 .. index:: Storage pool, simple
5918
5919 .. index:: Simple storage pool
5920
5921 Syntax:
5922
5923
5924 .. code-block:: ada
5925
5926 pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
5927
5928
5929 A type can be established as a 'simple storage pool type' by applying
5930 the representation pragma ``Simple_Storage_Pool_Type`` to the type.
5931 A type named in the pragma must be a library-level immutably limited record
5932 type or limited tagged type declared immediately within a package declaration.
5933 The type can also be a limited private type whose full type is allowed as
5934 a simple storage pool type.
5935
5936 For a simple storage pool type ``SSP``, nonabstract primitive subprograms
5937 ``Allocate``, ``Deallocate``, and ``Storage_Size`` can be declared that
5938 are subtype conformant with the following subprogram declarations:
5939
5940
5941 .. code-block:: ada
5942
5943 procedure Allocate
5944 (Pool : in out SSP;
5945 Storage_Address : out System.Address;
5946 Size_In_Storage_Elements : System.Storage_Elements.Storage_Count;
5947 Alignment : System.Storage_Elements.Storage_Count);
5948
5949 procedure Deallocate
5950 (Pool : in out SSP;
5951 Storage_Address : System.Address;
5952 Size_In_Storage_Elements : System.Storage_Elements.Storage_Count;
5953 Alignment : System.Storage_Elements.Storage_Count);
5954
5955 function Storage_Size (Pool : SSP)
5956 return System.Storage_Elements.Storage_Count;
5957
5958
5959 Procedure ``Allocate`` must be declared, whereas ``Deallocate`` and
5960 ``Storage_Size`` are optional. If ``Deallocate`` is not declared, then
5961 applying an unchecked deallocation has no effect other than to set its actual
5962 parameter to null. If ``Storage_Size`` is not declared, then the
5963 ``Storage_Size`` attribute applied to an access type associated with
5964 a pool object of type SSP returns zero. Additional operations can be declared
5965 for a simple storage pool type (such as for supporting a mark/release
5966 storage-management discipline).
5967
5968 An object of a simple storage pool type can be associated with an access
5969 type by specifying the attribute
5970 :ref:`Simple_Storage_Pool <Attribute_Simple_Storage_Pool>`. For example:
5971
5972
5973 .. code-block:: ada
5974
5975 My_Pool : My_Simple_Storage_Pool_Type;
5976
5977 type Acc is access My_Data_Type;
5978
5979 for Acc'Simple_Storage_Pool use My_Pool;
5980
5981
5982
5983 See attribute :ref:`Simple_Storage_Pool <Attribute_Simple_Storage_Pool>`
5984 for further details.
5985
5986 .. _Pragma_Source_File_Name:
5987
5988 Pragma Source_File_Name
5989 =======================
5990
5991 Syntax:
5992
5993
5994 ::
5995
5996 pragma Source_File_Name (
5997 [Unit_Name =>] unit_NAME,
5998 Spec_File_Name => STRING_LITERAL,
5999 [Index => INTEGER_LITERAL]);
6000
6001 pragma Source_File_Name (
6002 [Unit_Name =>] unit_NAME,
6003 Body_File_Name => STRING_LITERAL,
6004 [Index => INTEGER_LITERAL]);
6005
6006
6007 Use this to override the normal naming convention. It is a configuration
6008 pragma, and so has the usual applicability of configuration pragmas
6009 (i.e., it applies to either an entire partition, or to all units in a
6010 compilation, or to a single unit, depending on how it is used).
6011 ``unit_name`` is mapped to ``file_name_literal``. The identifier for
6012 the second argument is required, and indicates whether this is the file
6013 name for the spec or for the body.
6014
6015 The optional Index argument should be used when a file contains multiple
6016 units, and when you do not want to use ``gnatchop`` to separate then
6017 into multiple files (which is the recommended procedure to limit the
6018 number of recompilations that are needed when some sources change).
6019 For instance, if the source file :file:`source.ada` contains
6020
6021
6022 .. code-block:: ada
6023
6024 package B is
6025 ...
6026 end B;
6027
6028 with B;
6029 procedure A is
6030 begin
6031 ..
6032 end A;
6033
6034
6035 you could use the following configuration pragmas:
6036
6037
6038 .. code-block:: ada
6039
6040 pragma Source_File_Name
6041 (B, Spec_File_Name => "source.ada", Index => 1);
6042 pragma Source_File_Name
6043 (A, Body_File_Name => "source.ada", Index => 2);
6044
6045
6046 Note that the ``gnatname`` utility can also be used to generate those
6047 configuration pragmas.
6048
6049 Another form of the ``Source_File_Name`` pragma allows
6050 the specification of patterns defining alternative file naming schemes
6051 to apply to all files.
6052
6053
6054 ::
6055
6056 pragma Source_File_Name
6057 ( [Spec_File_Name =>] STRING_LITERAL
6058 [,[Casing =>] CASING_SPEC]
6059 [,[Dot_Replacement =>] STRING_LITERAL]);
6060
6061 pragma Source_File_Name
6062 ( [Body_File_Name =>] STRING_LITERAL
6063 [,[Casing =>] CASING_SPEC]
6064 [,[Dot_Replacement =>] STRING_LITERAL]);
6065
6066 pragma Source_File_Name
6067 ( [Subunit_File_Name =>] STRING_LITERAL
6068 [,[Casing =>] CASING_SPEC]
6069 [,[Dot_Replacement =>] STRING_LITERAL]);
6070
6071 CASING_SPEC ::= Lowercase | Uppercase | Mixedcase
6072
6073
6074 The first argument is a pattern that contains a single asterisk indicating
6075 the point at which the unit name is to be inserted in the pattern string
6076 to form the file name. The second argument is optional. If present it
6077 specifies the casing of the unit name in the resulting file name string.
6078 The default is lower case. Finally the third argument allows for systematic
6079 replacement of any dots in the unit name by the specified string literal.
6080
6081 Note that Source_File_Name pragmas should not be used if you are using
6082 project files. The reason for this rule is that the project manager is not
6083 aware of these pragmas, and so other tools that use the project file would not
6084 be aware of the intended naming conventions. If you are using project files,
6085 file naming is controlled by Source_File_Name_Project pragmas, which are
6086 usually supplied automatically by the project manager. A pragma
6087 Source_File_Name cannot appear after a :ref:`Pragma_Source_File_Name_Project`.
6088
6089 For more details on the use of the ``Source_File_Name`` pragma, see the
6090 sections on `Using Other File Names` and `Alternative File Naming Schemes`
6091 in the :title:`GNAT User's Guide`.
6092
6093 .. _Pragma_Source_File_Name_Project:
6094
6095 Pragma Source_File_Name_Project
6096 ===============================
6097
6098 This pragma has the same syntax and semantics as pragma Source_File_Name.
6099 It is only allowed as a stand-alone configuration pragma.
6100 It cannot appear after a :ref:`Pragma_Source_File_Name`, and
6101 most importantly, once pragma Source_File_Name_Project appears,
6102 no further Source_File_Name pragmas are allowed.
6103
6104 The intention is that Source_File_Name_Project pragmas are always
6105 generated by the Project Manager in a manner consistent with the naming
6106 specified in a project file, and when naming is controlled in this manner,
6107 it is not permissible to attempt to modify this naming scheme using
6108 Source_File_Name or Source_File_Name_Project pragmas (which would not be
6109 known to the project manager).
6110
6111 Pragma Source_Reference
6112 =======================
6113
6114 Syntax:
6115
6116
6117 .. code-block:: ada
6118
6119 pragma Source_Reference (INTEGER_LITERAL, STRING_LITERAL);
6120
6121
6122 This pragma must appear as the first line of a source file.
6123 ``integer_literal`` is the logical line number of the line following
6124 the pragma line (for use in error messages and debugging
6125 information). ``string_literal`` is a static string constant that
6126 specifies the file name to be used in error messages and debugging
6127 information. This is most notably used for the output of ``gnatchop``
6128 with the *-r* switch, to make sure that the original unchopped
6129 source file is the one referred to.
6130
6131 The second argument must be a string literal, it cannot be a static
6132 string expression other than a string literal. This is because its value
6133 is needed for error messages issued by all phases of the compiler.
6134
6135 .. _Pragma-SPARK_Mode:
6136
6137 Pragma SPARK_Mode
6138 =================
6139
6140 Syntax:
6141
6142
6143 ::
6144
6145 pragma SPARK_Mode [(On | Off)] ;
6146
6147
6148 In general a program can have some parts that are in SPARK 2014 (and
6149 follow all the rules in the SPARK Reference Manual), and some parts
6150 that are full Ada 2012.
6151
6152 The SPARK_Mode pragma is used to identify which parts are in SPARK
6153 2014 (by default programs are in full Ada). The SPARK_Mode pragma can
6154 be used in the following places:
6155
6156
6157 *
6158 As a configuration pragma, in which case it sets the default mode for
6159 all units compiled with this pragma.
6160
6161 *
6162 Immediately following a library-level subprogram spec
6163
6164 *
6165 Immediately within a library-level package body
6166
6167 *
6168 Immediately following the ``private`` keyword of a library-level
6169 package spec
6170
6171 *
6172 Immediately following the ``begin`` keyword of a library-level
6173 package body
6174
6175 *
6176 Immediately within a library-level subprogram body
6177
6178
6179 Normally a subprogram or package spec/body inherits the current mode
6180 that is active at the point it is declared. But this can be overridden
6181 by pragma within the spec or body as above.
6182
6183 The basic consistency rule is that you can't turn SPARK_Mode back
6184 ``On``, once you have explicitly (with a pragma) turned if
6185 ``Off``. So the following rules apply:
6186
6187 If a subprogram spec has SPARK_Mode ``Off``, then the body must
6188 also have SPARK_Mode ``Off``.
6189
6190 For a package, we have four parts:
6191
6192 *
6193 the package public declarations
6194 *
6195 the package private part
6196 *
6197 the body of the package
6198 *
6199 the elaboration code after ``begin``
6200
6201 For a package, the rule is that if you explicitly turn SPARK_Mode
6202 ``Off`` for any part, then all the following parts must have
6203 SPARK_Mode ``Off``. Note that this may require repeating a pragma
6204 SPARK_Mode (``Off``) in the body. For example, if we have a
6205 configuration pragma SPARK_Mode (``On``) that turns the mode on by
6206 default everywhere, and one particular package spec has pragma
6207 SPARK_Mode (``Off``), then that pragma will need to be repeated in
6208 the package body.
6209
6210 Pragma Static_Elaboration_Desired
6211 =================================
6212
6213 Syntax:
6214
6215
6216 .. code-block:: ada
6217
6218 pragma Static_Elaboration_Desired;
6219
6220
6221 This pragma is used to indicate that the compiler should attempt to initialize
6222 statically the objects declared in the library unit to which the pragma applies,
6223 when these objects are initialized (explicitly or implicitly) by an aggregate.
6224 In the absence of this pragma, aggregates in object declarations are expanded
6225 into assignments and loops, even when the aggregate components are static
6226 constants. When the aggregate is present the compiler builds a static expression
6227 that requires no run-time code, so that the initialized object can be placed in
6228 read-only data space. If the components are not static, or the aggregate has
6229 more that 100 components, the compiler emits a warning that the pragma cannot
6230 be obeyed. (See also the restriction No_Implicit_Loops, which supports static
6231 construction of larger aggregates with static components that include an others
6232 choice.)
6233
6234 Pragma Stream_Convert
6235 =====================
6236
6237 Syntax:
6238
6239
6240 ::
6241
6242 pragma Stream_Convert (
6243 [Entity =>] type_LOCAL_NAME,
6244 [Read =>] function_NAME,
6245 [Write =>] function_NAME);
6246
6247
6248 This pragma provides an efficient way of providing user-defined stream
6249 attributes. Not only is it simpler to use than specifying the attributes
6250 directly, but more importantly, it allows the specification to be made in such
6251 a way that the predefined unit Ada.Streams is not loaded unless it is actually
6252 needed (i.e. unless the stream attributes are actually used); the use of
6253 the Stream_Convert pragma adds no overhead at all, unless the stream
6254 attributes are actually used on the designated type.
6255
6256 The first argument specifies the type for which stream functions are
6257 provided. The second parameter provides a function used to read values
6258 of this type. It must name a function whose argument type may be any
6259 subtype, and whose returned type must be the type given as the first
6260 argument to the pragma.
6261
6262 The meaning of the ``Read`` parameter is that if a stream attribute directly
6263 or indirectly specifies reading of the type given as the first parameter,
6264 then a value of the type given as the argument to the Read function is
6265 read from the stream, and then the Read function is used to convert this
6266 to the required target type.
6267
6268 Similarly the ``Write`` parameter specifies how to treat write attributes
6269 that directly or indirectly apply to the type given as the first parameter.
6270 It must have an input parameter of the type specified by the first parameter,
6271 and the return type must be the same as the input type of the Read function.
6272 The effect is to first call the Write function to convert to the given stream
6273 type, and then write the result type to the stream.
6274
6275 The Read and Write functions must not be overloaded subprograms. If necessary
6276 renamings can be supplied to meet this requirement.
6277 The usage of this attribute is best illustrated by a simple example, taken
6278 from the GNAT implementation of package Ada.Strings.Unbounded:
6279
6280
6281 .. code-block:: ada
6282
6283 function To_Unbounded (S : String) return Unbounded_String
6284 renames To_Unbounded_String;
6285
6286 pragma Stream_Convert
6287 (Unbounded_String, To_Unbounded, To_String);
6288
6289
6290 The specifications of the referenced functions, as given in the Ada
6291 Reference Manual are:
6292
6293
6294 .. code-block:: ada
6295
6296 function To_Unbounded_String (Source : String)
6297 return Unbounded_String;
6298
6299 function To_String (Source : Unbounded_String)
6300 return String;
6301
6302
6303 The effect is that if the value of an unbounded string is written to a stream,
6304 then the representation of the item in the stream is in the same format that
6305 would be used for ``Standard.String'Output``, and this same representation
6306 is expected when a value of this type is read from the stream. Note that the
6307 value written always includes the bounds, even for Unbounded_String'Write,
6308 since Unbounded_String is not an array type.
6309
6310 Note that the ``Stream_Convert`` pragma is not effective in the case of
6311 a derived type of a non-limited tagged type. If such a type is specified then
6312 the pragma is silently ignored, and the default implementation of the stream
6313 attributes is used instead.
6314
6315 Pragma Style_Checks
6316 ===================
6317
6318 Syntax:
6319
6320
6321 ::
6322
6323 pragma Style_Checks (string_LITERAL | ALL_CHECKS |
6324 On | Off [, LOCAL_NAME]);
6325
6326
6327 This pragma is used in conjunction with compiler switches to control the
6328 built in style checking provided by GNAT. The compiler switches, if set,
6329 provide an initial setting for the switches, and this pragma may be used
6330 to modify these settings, or the settings may be provided entirely by
6331 the use of the pragma. This pragma can be used anywhere that a pragma
6332 is legal, including use as a configuration pragma (including use in
6333 the :file:`gnat.adc` file).
6334
6335 The form with a string literal specifies which style options are to be
6336 activated. These are additive, so they apply in addition to any previously
6337 set style check options. The codes for the options are the same as those
6338 used in the *-gnaty* switch to *gcc* or *gnatmake*.
6339 For example the following two methods can be used to enable
6340 layout checking and to change the maximum nesting level value:
6341
6342 *
6343
6344 .. code-block:: ada
6345
6346 -- switch on layout checks
6347 pragma Style_Checks ("l");
6348 -- set the number of maximum allowed nesting levels to 15
6349 pragma Style_Checks ("L15");
6350
6351 *
6352
6353 ::
6354
6355 gcc -c -gnatyl -gnatyL15 ...
6356
6357
6358 The string literal values can be cumulatively switched on and off by prefixing
6359 the value with ``+`` or ``-``, where:
6360
6361 * ``+`` is equivalent to no prefix. It applies the check referenced by the
6362 literal value;
6363 * ``-`` switches the referenced check off.
6364
6365
6366 .. code-block:: ada
6367 :linenos:
6368 :emphasize-lines: 15
6369
6370 -- allow misaligned block by disabling layout check
6371 pragma Style_Checks ("-l");
6372 declare
6373 msg : constant String := "Hello";
6374 begin
6375 Put_Line (msg);
6376 end;
6377
6378 -- enable the layout check again
6379 pragma Style_Checks ("l");
6380 declare
6381 msg : constant String := "Hello";
6382 begin
6383 Put_Line (msg);
6384 end;
6385
6386 The code above contains two layout errors, however, only
6387 the last line is picked up by the compiler.
6388
6389 Similarly, the switches containing a numeric value can be applied in sequence.
6390 In the example below, the permitted nesting level is reduced in in the middle
6391 block and the compiler raises a warning on the highlighted line.
6392
6393 .. code-block:: ada
6394 :linenos:
6395 :emphasize-lines: 15
6396
6397 -- Permit 3 levels of nesting
6398 pragma Style_Checks ("L3");
6399
6400 procedure Main is
6401 begin
6402 if True then
6403 if True then
6404 null;
6405 end if;
6406 end if;
6407 -- Reduce permitted nesting levels to 2.
6408 -- Note that "+L2" and "L2" are equivalent.
6409 pragma Style_Checks ("+L2");
6410 if True then
6411 if True then
6412 null;
6413 end if;
6414 end if;
6415 -- Disable checking permitted nesting levels.
6416 -- Note that the number after "-L" is insignificant,
6417 -- "-L", "-L3" and "-Lx" are all equivalent.
6418 pragma Style_Checks ("-L3");
6419 if True then
6420 if True then
6421 null;
6422 end if;
6423 end if;
6424 end Main;
6425
6426 The form ``ALL_CHECKS`` activates all standard checks (its use is equivalent
6427 to the use of the :switch:`gnaty` switch with no options.
6428 See the :title:`GNAT User's Guide` for details.)
6429
6430 Note: the behavior is slightly different in GNAT mode (:switch:`-gnatg` used).
6431 In this case, ``ALL_CHECKS`` implies the standard set of GNAT mode style check
6432 options (i.e. equivalent to :switch:`-gnatyg`).
6433
6434 The forms with ``Off`` and ``On``
6435 can be used to temporarily disable style checks
6436 as shown in the following example:
6437
6438 .. code-block:: ada
6439
6440 pragma Style_Checks ("k"); -- requires keywords in lower case
6441 pragma Style_Checks (Off); -- turn off style checks
6442 NULL; -- this will not generate an error message
6443 pragma Style_Checks (On); -- turn style checks back on
6444 NULL; -- this will generate an error message
6445
6446
6447 Finally the two argument form is allowed only if the first argument is
6448 ``On`` or ``Off``. The effect is to turn of semantic style checks
6449 for the specified entity, as shown in the following example:
6450
6451
6452 .. code-block:: ada
6453
6454 pragma Style_Checks ("r"); -- require consistency of identifier casing
6455 Arg : Integer;
6456 Rf1 : Integer := ARG; -- incorrect, wrong case
6457 pragma Style_Checks (Off, Arg);
6458 Rf2 : Integer := ARG; -- OK, no error
6459
6460 Pragma Subprogram_Variant
6461 =========================
6462 .. index:: Subprogram_Variant
6463
6464 Syntax:
6465
6466
6467 ::
6468
6469 pragma Subprogram_Variant (SUBPROGRAM_VARIANT_LIST);
6470
6471 SUBPROGRAM_VARIANT_LIST ::=
6472 STRUCTURAL_SUBPROGRAM_VARIANT_ITEM
6473 | NUMERIC_SUBPROGRAM_VARIANT_ITEMS
6474
6475 NUMERIC_SUBPROGRAM_VARIANT_ITEMS ::=
6476 NUMERIC_SUBPROGRAM_VARIANT_ITEM {, NUMERIC_SUBPROGRAM_VARIANT_ITEM}
6477
6478 NUMERIC_SUBPROGRAM_VARIANT_ITEM ::=
6479 CHANGE_DIRECTION => EXPRESSION
6480
6481 STRUCTURAL_SUBPROGRAM_VARIANT_ITEM ::=
6482 STRUCTURAL => EXPRESSION
6483
6484 CHANGE_DIRECTION ::= Increases | Decreases
6485
6486 The ``Subprogram_Variant`` pragma is intended to be an exact replacement for
6487 the implementation-defined ``Subprogram_Variant`` aspect, and shares its
6488 restrictions and semantics.
6489
6490
6491 Pragma Subtitle
6492 ===============
6493
6494 Syntax:
6495
6496
6497 ::
6498
6499 pragma Subtitle ([Subtitle =>] STRING_LITERAL);
6500
6501
6502 This pragma is recognized for compatibility with other Ada compilers
6503 but is ignored by GNAT.
6504
6505 Pragma Suppress
6506 ===============
6507
6508 Syntax:
6509
6510
6511 ::
6512
6513 pragma Suppress (Identifier [, [On =>] Name]);
6514
6515
6516 This is a standard pragma, and supports all the check names required in
6517 the RM. It is included here because GNAT recognizes some additional check
6518 names that are implementation defined (as permitted by the RM):
6519
6520
6521 *
6522 ``Alignment_Check`` can be used to suppress alignment checks
6523 on addresses used in address clauses. Such checks can also be suppressed
6524 by suppressing range checks, but the specific use of ``Alignment_Check``
6525 allows suppression of alignment checks without suppressing other range checks.
6526 Note that ``Alignment_Check`` is suppressed by default on machines (such as
6527 the x86) with non-strict alignment.
6528
6529 *
6530 ``Atomic_Synchronization`` can be used to suppress the special memory
6531 synchronization instructions that are normally generated for access to
6532 ``Atomic`` variables to ensure correct synchronization between tasks
6533 that use such variables for synchronization purposes.
6534
6535 *
6536 ``Duplicated_Tag_Check`` Can be used to suppress the check that is generated
6537 for a duplicated tag value when a tagged type is declared.
6538
6539 *
6540 ``Container_Checks`` Can be used to suppress all checks within Ada.Containers
6541 and instances of its children, including Tampering_Check.
6542
6543 *
6544 ``Tampering_Check`` Can be used to suppress tampering check in the containers.
6545
6546 *
6547 ``Predicate_Check`` can be used to control whether predicate checks are
6548 active. It is applicable only to predicates for which the policy is
6549 ``Check``. Unlike ``Assertion_Policy``, which determines if a given
6550 predicate is ignored or checked for the whole program, the use of
6551 ``Suppress`` and ``Unsuppress`` with this check name allows a given
6552 predicate to be turned on and off at specific points in the program.
6553
6554 *
6555 ``Validity_Check`` can be used specifically to control validity checks.
6556 If ``Suppress`` is used to suppress validity checks, then no validity
6557 checks are performed, including those specified by the appropriate compiler
6558 switch or the ``Validity_Checks`` pragma.
6559
6560 *
6561 Additional check names previously introduced by use of the ``Check_Name``
6562 pragma are also allowed.
6563
6564
6565 Note that pragma Suppress gives the compiler permission to omit
6566 checks, but does not require the compiler to omit checks. The compiler
6567 will generate checks if they are essentially free, even when they are
6568 suppressed. In particular, if the compiler can prove that a certain
6569 check will necessarily fail, it will generate code to do an
6570 unconditional 'raise', even if checks are suppressed. The compiler
6571 warns in this case.
6572
6573 Of course, run-time checks are omitted whenever the compiler can prove
6574 that they will not fail, whether or not checks are suppressed.
6575
6576 Pragma Suppress_All
6577 ===================
6578
6579 Syntax:
6580
6581
6582 .. code-block:: ada
6583
6584 pragma Suppress_All;
6585
6586
6587 This pragma can appear anywhere within a unit.
6588 The effect is to apply ``Suppress (All_Checks)`` to the unit
6589 in which it appears. This pragma is implemented for compatibility with DEC
6590 Ada 83 usage where it appears at the end of a unit, and for compatibility
6591 with Rational Ada, where it appears as a program unit pragma.
6592 The use of the standard Ada pragma ``Suppress (All_Checks)``
6593 as a normal configuration pragma is the preferred usage in GNAT.
6594
6595 .. _Pragma-Suppress_Debug_Info:
6596
6597 Pragma Suppress_Debug_Info
6598 ==========================
6599
6600 Syntax:
6601
6602
6603 ::
6604
6605 pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
6606
6607
6608 This pragma can be used to suppress generation of debug information
6609 for the specified entity. It is intended primarily for use in debugging
6610 the debugger, and navigating around debugger problems.
6611
6612 Pragma Suppress_Exception_Locations
6613 ===================================
6614
6615 Syntax:
6616
6617
6618 .. code-block:: ada
6619
6620 pragma Suppress_Exception_Locations;
6621
6622
6623 In normal mode, a raise statement for an exception by default generates
6624 an exception message giving the file name and line number for the location
6625 of the raise. This is useful for debugging and logging purposes, but this
6626 entails extra space for the strings for the messages. The configuration
6627 pragma ``Suppress_Exception_Locations`` can be used to suppress the
6628 generation of these strings, with the result that space is saved, but the
6629 exception message for such raises is null. This configuration pragma may
6630 appear in a global configuration pragma file, or in a specific unit as
6631 usual. It is not required that this pragma be used consistently within
6632 a partition, so it is fine to have some units within a partition compiled
6633 with this pragma and others compiled in normal mode without it.
6634
6635 .. _Pragma-Suppress_Initialization:
6636
6637 Pragma Suppress_Initialization
6638 ==============================
6639 .. index:: Suppressing initialization
6640
6641 .. index:: Initialization, suppression of
6642
6643 Syntax:
6644
6645
6646 ::
6647
6648 pragma Suppress_Initialization ([Entity =>] variable_or_subtype_LOCAL_NAME);
6649
6650
6651 Here variable_or_subtype_LOCAL_NAME is the name introduced by a type
6652 declaration or subtype declaration or the name of a variable introduced by
6653 an object declaration.
6654
6655 In the case of a type or subtype
6656 this pragma suppresses any implicit or explicit initialization
6657 for all variables of the given type or subtype,
6658 including initialization resulting from the use of pragmas
6659 Normalize_Scalars or Initialize_Scalars.
6660
6661 This is considered a representation item, so it cannot be given after
6662 the type is frozen. It applies to all subsequent object declarations,
6663 and also any allocator that creates objects of the type.
6664
6665 If the pragma is given for the first subtype, then it is considered
6666 to apply to the base type and all its subtypes. If the pragma is given
6667 for other than a first subtype, then it applies only to the given subtype.
6668 The pragma may not be given after the type is frozen.
6669
6670 Note that this includes eliminating initialization of discriminants
6671 for discriminated types, and tags for tagged types. In these cases,
6672 you will have to use some non-portable mechanism (e.g. address
6673 overlays or unchecked conversion) to achieve required initialization
6674 of these fields before accessing any object of the corresponding type.
6675
6676 For the variable case, implicit initialization for the named variable
6677 is suppressed, just as though its subtype had been given in a pragma
6678 Suppress_Initialization, as described above.
6679
6680 Pragma Task_Name
6681 ================
6682
6683 Syntax
6684
6685
6686 .. code-block:: ada
6687
6688 pragma Task_Name (string_EXPRESSION);
6689
6690
6691 This pragma appears within a task definition (like pragma
6692 ``Priority``) and applies to the task in which it appears. The
6693 argument must be of type String, and provides a name to be used for
6694 the task instance when the task is created. Note that this expression
6695 is not required to be static, and in particular, it can contain
6696 references to task discriminants. This facility can be used to
6697 provide different names for different tasks as they are created,
6698 as illustrated in the example below.
6699
6700 The task name is recorded internally in the run-time structures
6701 and is accessible to tools like the debugger. In addition the
6702 routine ``Ada.Task_Identification.Image`` will return this
6703 string, with a unique task address appended.
6704
6705
6706 .. code-block:: ada
6707
6708 -- Example of the use of pragma Task_Name
6709
6710 with Ada.Task_Identification;
6711 use Ada.Task_Identification;
6712 with Text_IO; use Text_IO;
6713 procedure t3 is
6714
6715 type Astring is access String;
6716
6717 task type Task_Typ (Name : access String) is
6718 pragma Task_Name (Name.all);
6719 end Task_Typ;
6720
6721 task body Task_Typ is
6722 Nam : constant String := Image (Current_Task);
6723 begin
6724 Put_Line ("-->" & Nam (1 .. 14) & "<--");
6725 end Task_Typ;
6726
6727 type Ptr_Task is access Task_Typ;
6728 Task_Var : Ptr_Task;
6729
6730 begin
6731 Task_Var :=
6732 new Task_Typ (new String'("This is task 1"));
6733 Task_Var :=
6734 new Task_Typ (new String'("This is task 2"));
6735 end;
6736
6737
6738 Pragma Task_Storage
6739 ===================
6740 Syntax:
6741
6742
6743 ::
6744
6745 pragma Task_Storage (
6746 [Task_Type =>] LOCAL_NAME,
6747 [Top_Guard =>] static_integer_EXPRESSION);
6748
6749
6750 This pragma specifies the length of the guard area for tasks. The guard
6751 area is an additional storage area allocated to a task. A value of zero
6752 means that either no guard area is created or a minimal guard area is
6753 created, depending on the target. This pragma can appear anywhere a
6754 ``Storage_Size`` attribute definition clause is allowed for a task
6755 type.
6756
6757 .. _Pragma-Test_Case:
6758
6759 Pragma Test_Case
6760 ================
6761 .. index:: Test cases
6762
6763
6764 Syntax:
6765
6766
6767 ::
6768
6769 pragma Test_Case (
6770 [Name =>] static_string_Expression
6771 ,[Mode =>] (Nominal | Robustness)
6772 [, Requires => Boolean_Expression]
6773 [, Ensures => Boolean_Expression]);
6774
6775
6776 The ``Test_Case`` pragma allows defining fine-grain specifications
6777 for use by testing tools.
6778 The compiler checks the validity of the ``Test_Case`` pragma, but its
6779 presence does not lead to any modification of the code generated by the
6780 compiler.
6781
6782 ``Test_Case`` pragmas may only appear immediately following the
6783 (separate) declaration of a subprogram in a package declaration, inside
6784 a package spec unit. Only other pragmas may intervene (that is appear
6785 between the subprogram declaration and a test case).
6786
6787 The compiler checks that boolean expressions given in ``Requires`` and
6788 ``Ensures`` are valid, where the rules for ``Requires`` are the
6789 same as the rule for an expression in ``Precondition`` and the rules
6790 for ``Ensures`` are the same as the rule for an expression in
6791 ``Postcondition``. In particular, attributes ``'Old`` and
6792 ``'Result`` can only be used within the ``Ensures``
6793 expression. The following is an example of use within a package spec:
6794
6795
6796 .. code-block:: ada
6797
6798 package Math_Functions is
6799 ...
6800 function Sqrt (Arg : Float) return Float;
6801 pragma Test_Case (Name => "Test 1",
6802 Mode => Nominal,
6803 Requires => Arg < 10000.0,
6804 Ensures => Sqrt'Result < 10.0);
6805 ...
6806 end Math_Functions;
6807
6808
6809 The meaning of a test case is that there is at least one context where
6810 ``Requires`` holds such that, if the associated subprogram is executed in
6811 that context, then ``Ensures`` holds when the subprogram returns.
6812 Mode ``Nominal`` indicates that the input context should also satisfy the
6813 precondition of the subprogram, and the output context should also satisfy its
6814 postcondition. Mode ``Robustness`` indicates that the precondition and
6815 postcondition of the subprogram should be ignored for this test case.
6816
6817 .. _Pragma-Thread_Local_Storage:
6818
6819 Pragma Thread_Local_Storage
6820 ===========================
6821 .. index:: Task specific storage
6822
6823 .. index:: TLS (Thread Local Storage)
6824
6825 .. index:: Task_Attributes
6826
6827 Syntax:
6828
6829
6830 ::
6831
6832 pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
6833
6834
6835 This pragma specifies that the specified entity, which must be
6836 a variable declared in a library-level package, is to be marked as
6837 "Thread Local Storage" (``TLS``). On systems supporting this (which
6838 include Windows, Solaris, GNU/Linux, and VxWorks), this causes each
6839 thread (and hence each Ada task) to see a distinct copy of the variable.
6840
6841 The variable must not have default initialization, and if there is
6842 an explicit initialization, it must be either ``null`` for an
6843 access variable, a static expression for a scalar variable, or a fully
6844 static aggregate for a composite type, that is to say, an aggregate all
6845 of whose components are static, and which does not include packed or
6846 discriminated components.
6847
6848 This provides a low-level mechanism similar to that provided by
6849 the ``Ada.Task_Attributes`` package, but much more efficient
6850 and is also useful in writing interface code that will interact
6851 with foreign threads.
6852
6853 If this pragma is used on a system where ``TLS`` is not supported,
6854 then an error message will be generated and the program will be rejected.
6855
6856 Pragma Time_Slice
6857 =================
6858
6859 Syntax:
6860
6861
6862 .. code-block:: ada
6863
6864 pragma Time_Slice (static_duration_EXPRESSION);
6865
6866
6867 For implementations of GNAT on operating systems where it is possible
6868 to supply a time slice value, this pragma may be used for this purpose.
6869 It is ignored if it is used in a system that does not allow this control,
6870 or if it appears in other than the main program unit.
6871
6872 Pragma Title
6873 ============
6874
6875 Syntax:
6876
6877
6878 ::
6879
6880 pragma Title (TITLING_OPTION [, TITLING OPTION]);
6881
6882 TITLING_OPTION ::=
6883 [Title =>] STRING_LITERAL,
6884 | [Subtitle =>] STRING_LITERAL
6885
6886
6887 Syntax checked but otherwise ignored by GNAT. This is a listing control
6888 pragma used in DEC Ada 83 implementations to provide a title and/or
6889 subtitle for the program listing. The program listing generated by GNAT
6890 does not have titles or subtitles.
6891
6892 Unlike other pragmas, the full flexibility of named notation is allowed
6893 for this pragma, i.e., the parameters may be given in any order if named
6894 notation is used, and named and positional notation can be mixed
6895 following the normal rules for procedure calls in Ada.
6896
6897 Pragma Type_Invariant
6898 =====================
6899
6900 Syntax:
6901
6902
6903 ::
6904
6905 pragma Type_Invariant
6906 ([Entity =>] type_LOCAL_NAME,
6907 [Check =>] EXPRESSION);
6908
6909
6910 The ``Type_Invariant`` pragma is intended to be an exact
6911 replacement for the language-defined ``Type_Invariant``
6912 aspect, and shares its restrictions and semantics. It differs
6913 from the language defined ``Invariant`` pragma in that it
6914 does not permit a string parameter, and it is
6915 controlled by the assertion identifier ``Type_Invariant``
6916 rather than ``Invariant``.
6917
6918 .. _Pragma-Type_Invariant_Class:
6919
6920 Pragma Type_Invariant_Class
6921 ===========================
6922
6923 Syntax:
6924
6925
6926 ::
6927
6928 pragma Type_Invariant_Class
6929 ([Entity =>] type_LOCAL_NAME,
6930 [Check =>] EXPRESSION);
6931
6932
6933 The ``Type_Invariant_Class`` pragma is intended to be an exact
6934 replacement for the language-defined ``Type_Invariant'Class``
6935 aspect, and shares its restrictions and semantics.
6936
6937 Note: This pragma is called ``Type_Invariant_Class`` rather than
6938 ``Type_Invariant'Class`` because the latter would not be strictly
6939 conforming to the allowed syntax for pragmas. The motivation
6940 for providing pragmas equivalent to the aspects is to allow a program
6941 to be written using the pragmas, and then compiled if necessary
6942 using an Ada compiler that does not recognize the pragmas or
6943 aspects, but is prepared to ignore the pragmas. The assertion
6944 policy that controls this pragma is ``Type_Invariant'Class``,
6945 not ``Type_Invariant_Class``.
6946
6947 Pragma Unchecked_Union
6948 ======================
6949 .. index:: Unions in C
6950
6951
6952 Syntax:
6953
6954
6955 .. code-block:: ada
6956
6957 pragma Unchecked_Union (first_subtype_LOCAL_NAME);
6958
6959
6960 This pragma is used to specify a representation of a record type that is
6961 equivalent to a C union. It was introduced as a GNAT implementation defined
6962 pragma in the GNAT Ada 95 mode. Ada 2005 includes an extended version of this
6963 pragma, making it language defined, and GNAT fully implements this extended
6964 version in all language modes (Ada 83, Ada 95, and Ada 2005). For full
6965 details, consult the Ada 2012 Reference Manual, section B.3.3.
6966
6967 Pragma Unevaluated_Use_Of_Old
6968 =============================
6969 .. index:: Attribute Old
6970
6971 .. index:: Attribute Loop_Entry
6972
6973 .. index:: Unevaluated_Use_Of_Old
6974
6975
6976 Syntax:
6977
6978
6979 .. code-block:: ada
6980
6981 pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
6982
6983
6984 This pragma controls the processing of attributes Old and Loop_Entry.
6985 If either of these attributes is used in a potentially unevaluated
6986 expression (e.g. the then or else parts of an if expression), then
6987 normally this usage is considered illegal if the prefix of the attribute
6988 is other than an entity name. The language requires this
6989 behavior for Old, and GNAT copies the same rule for Loop_Entry.
6990
6991 The reason for this rule is that otherwise, we can have a situation
6992 where we save the Old value, and this results in an exception, even
6993 though we might not evaluate the attribute. Consider this example:
6994
6995
6996 .. code-block:: ada
6997
6998 package UnevalOld is
6999 K : Character;
7000 procedure U (A : String; C : Boolean) -- ERROR
7001 with Post => (if C then A(1)'Old = K else True);
7002 end;
7003
7004
7005 If procedure U is called with a string with a lower bound of 2, and
7006 C false, then an exception would be raised trying to evaluate A(1)
7007 on entry even though the value would not be actually used.
7008
7009 Although the rule guarantees against this possibility, it is sometimes
7010 too restrictive. For example if we know that the string has a lower
7011 bound of 1, then we will never raise an exception.
7012 The pragma ``Unevaluated_Use_Of_Old`` can be
7013 used to modify this behavior. If the argument is ``Error`` then an
7014 error is given (this is the default RM behavior). If the argument is
7015 ``Warn`` then the usage is allowed as legal but with a warning
7016 that an exception might be raised. If the argument is ``Allow``
7017 then the usage is allowed as legal without generating a warning.
7018
7019 This pragma may appear as a configuration pragma, or in a declarative
7020 part or package specification. In the latter case it applies to
7021 uses up to the end of the corresponding statement sequence or
7022 sequence of package declarations.
7023
7024 Pragma User_Aspect_Definition
7025 =============================
7026
7027 Syntax:
7028
7029
7030 .. code-block:: ada
7031
7032 pragma User_Aspect_Definition
7033 (Identifier {, Identifier [(Identifier {, Identifier})]});
7034
7035
7036 This configuration pragma defines a new aspect, making it available for
7037 subsequent use in a `User_Aspect` aspect specification. The first identifier
7038 is the name of the new aspect. Any subsequent arguments specify the names
7039 of other aspects. A subsequent name for which no parenthesized arguments
7040 are given shall denote either a Boolean-valued non-representation aspect
7041 or an aspect that has been defined by another `User_Aspect_Definition`
7042 pragma. A name for which one or more arguments are given shall be either
7043 `Annotate` or `Local_Restrictions` (and the arguments shall be appropriate
7044 for the named aspect).
7045
7046 This pragma, together with the `User_Aspect` aspect, provides a mechanism
7047 for avoiding textual duplication if some set of aspect specifications
7048 is needed in multiple places. This is somewhat analogous to how profiles
7049 allow avoiding duplication of `Restrictions` pragmas.
7050
7051 The visibility rules for an aspect defined by a `User_Aspect_Definition`
7052 pragma are the same as for a check name introduced by a `Check_Name`
7053 pragma. If multiple definitions are visible for some aspect at some point,
7054 then the definitions must agree. A predefined aspect cannot be redefined.
7055
7056
7057 Pragma Unimplemented_Unit
7058 =========================
7059
7060 Syntax:
7061
7062
7063 .. code-block:: ada
7064
7065 pragma Unimplemented_Unit;
7066
7067
7068 If this pragma occurs in a unit that is processed by the compiler, GNAT
7069 aborts with the message :samp:`xxx is not supported in this configuration`,
7070 where ``xxx`` is the name of the current compilation unit. This pragma
7071 is intended to allow the compiler to handle unimplemented library units in
7072 a clean manner.
7073
7074 The abort only happens if code is being generated. Thus you can use
7075 specs of unimplemented packages in syntax or semantic checking mode.
7076
7077 .. _Pragma-Universal_Aliasing:
7078
7079 Pragma Universal_Aliasing
7080 =========================
7081
7082 Syntax:
7083
7084
7085 ::
7086
7087 pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
7088
7089
7090 ``type_LOCAL_NAME`` must refer to a type declaration in the current
7091 declarative part. The effect is to inhibit strict type-based aliasing
7092 optimizations for the given type. For a detailed description of the
7093 strict type-based aliasing optimizations and the situations in which
7094 they need to be suppressed, see the section on
7095 ``Optimization and Strict Aliasing`` in the :title:`GNAT User's Guide`.
7096
7097 .. _Pragma-Unmodified:
7098
7099 Pragma Unmodified
7100 =================
7101 .. index:: Warnings, unmodified
7102
7103 Syntax:
7104
7105
7106 ::
7107
7108 pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
7109
7110
7111 This pragma signals that the assignable entities (variables,
7112 ``out`` parameters, ``in out`` parameters) whose names are listed are
7113 deliberately not assigned in the current source unit. This
7114 suppresses warnings about the
7115 entities being referenced but not assigned, and in addition a warning will be
7116 generated if one of these entities is in fact assigned in the
7117 same unit as the pragma (or in the corresponding body, or one
7118 of its subunits).
7119
7120 This is particularly useful for clearly signaling that a particular
7121 parameter is not modified, even though the spec suggests that it might
7122 be.
7123
7124 For the variable case, warnings are never given for unreferenced variables
7125 whose name contains one of the substrings
7126 ``DISCARD, DUMMY, IGNORE, JUNK, UNUSE, TMP, TEMP`` in any casing. Such names
7127 are typically to be used in cases where such warnings are expected.
7128 Thus it is never necessary to use ``pragma Unmodified`` for such
7129 variables, though it is harmless to do so.
7130
7131 .. _Pragma-Unreferenced:
7132
7133 Pragma Unreferenced
7134 ===================
7135 .. index:: Warnings, unreferenced
7136
7137 Syntax:
7138
7139
7140 ::
7141
7142 pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
7143 pragma Unreferenced (library_unit_NAME {, library_unit_NAME});
7144
7145
7146 This pragma signals that the entities whose names are listed are
7147 deliberately not referenced in the current source unit after the
7148 occurrence of the pragma. This
7149 suppresses warnings about the
7150 entities being unreferenced, and in addition a warning will be
7151 generated if one of these entities is in fact subsequently referenced in the
7152 same unit as the pragma (or in the corresponding body, or one
7153 of its subunits).
7154
7155 This is particularly useful for clearly signaling that a particular
7156 parameter is not referenced in some particular subprogram implementation
7157 and that this is deliberate. It can also be useful in the case of
7158 objects declared only for their initialization or finalization side
7159 effects.
7160
7161 If ``LOCAL_NAME`` identifies more than one matching homonym in the
7162 current scope, then the entity most recently declared is the one to which
7163 the pragma applies. Note that in the case of accept formals, the pragma
7164 Unreferenced may appear immediately after the keyword ``do`` which
7165 allows the indication of whether or not accept formals are referenced
7166 or not to be given individually for each accept statement.
7167
7168 The left hand side of an assignment does not count as a reference for the
7169 purpose of this pragma. Thus it is fine to assign to an entity for which
7170 pragma Unreferenced is given. However, use of an entity as an actual for
7171 an out parameter does count as a reference unless warnings for unread output
7172 parameters are enabled via :switch:`-gnatw.o`.
7173
7174 Note that if a warning is desired for all calls to a given subprogram,
7175 regardless of whether they occur in the same unit as the subprogram
7176 declaration, then this pragma should not be used (calls from another
7177 unit would not be flagged); pragma Obsolescent can be used instead
7178 for this purpose, see :ref:`Pragma_Obsolescent`.
7179
7180 The second form of pragma ``Unreferenced`` is used within a context
7181 clause. In this case the arguments must be unit names of units previously
7182 mentioned in ``with`` clauses (similar to the usage of pragma
7183 ``Elaborate_All``). The effect is to suppress warnings about unreferenced
7184 units and unreferenced entities within these units.
7185
7186 For the variable case, warnings are never given for unreferenced variables
7187 whose name contains one of the substrings
7188 ``DISCARD, DUMMY, IGNORE, JUNK, UNUSED`` in any casing. Such names
7189 are typically to be used in cases where such warnings are expected.
7190 Thus it is never necessary to use ``pragma Unreferenced`` for such
7191 variables, though it is harmless to do so.
7192
7193 .. _Pragma-Unreferenced_Objects:
7194
7195 Pragma Unreferenced_Objects
7196 ===========================
7197 .. index:: Warnings, unreferenced
7198
7199 Syntax:
7200
7201
7202 ::
7203
7204 pragma Unreferenced_Objects (local_subtype_NAME {, local_subtype_NAME});
7205
7206
7207 This pragma signals that for the types or subtypes whose names are
7208 listed, objects which are declared with one of these types or subtypes may
7209 not be referenced, and if no references appear, no warnings are given.
7210
7211 This is particularly useful for objects which are declared solely for their
7212 initialization and finalization effect. Such variables are sometimes referred
7213 to as RAII variables (Resource Acquisition Is Initialization). Using this
7214 pragma on the relevant type (most typically a limited controlled type), the
7215 compiler will automatically suppress unwanted warnings about these variables
7216 not being referenced.
7217
7218 Pragma Unreserve_All_Interrupts
7219 ===============================
7220
7221 Syntax:
7222
7223
7224 .. code-block:: ada
7225
7226 pragma Unreserve_All_Interrupts;
7227
7228
7229 Normally certain interrupts are reserved to the implementation. Any attempt
7230 to attach an interrupt causes Program_Error to be raised, as described in
7231 RM C.3.2(22). A typical example is the ``SIGINT`` interrupt used in
7232 many systems for a :kbd:`Ctrl-C` interrupt. Normally this interrupt is
7233 reserved to the implementation, so that :kbd:`Ctrl-C` can be used to
7234 interrupt execution.
7235
7236 If the pragma ``Unreserve_All_Interrupts`` appears anywhere in any unit in
7237 a program, then all such interrupts are unreserved. This allows the
7238 program to handle these interrupts, but disables their standard
7239 functions. For example, if this pragma is used, then pressing
7240 :kbd:`Ctrl-C` will not automatically interrupt execution. However,
7241 a program can then handle the ``SIGINT`` interrupt as it chooses.
7242
7243 For a full list of the interrupts handled in a specific implementation,
7244 see the source code for the spec of ``Ada.Interrupts.Names`` in
7245 file :file:`a-intnam.ads`. This is a target dependent file that contains the
7246 list of interrupts recognized for a given target. The documentation in
7247 this file also specifies what interrupts are affected by the use of
7248 the ``Unreserve_All_Interrupts`` pragma.
7249
7250 For a more general facility for controlling what interrupts can be
7251 handled, see pragma ``Interrupt_State``, which subsumes the functionality
7252 of the ``Unreserve_All_Interrupts`` pragma.
7253
7254 Pragma Unsuppress
7255 =================
7256
7257 Syntax:
7258
7259
7260 ::
7261
7262 pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
7263
7264
7265 This pragma undoes the effect of a previous pragma ``Suppress``. If
7266 there is no corresponding pragma ``Suppress`` in effect, it has no
7267 effect. The range of the effect is the same as for pragma
7268 ``Suppress``. The meaning of the arguments is identical to that used
7269 in pragma ``Suppress``.
7270
7271 One important application is to ensure that checks are on in cases where
7272 code depends on the checks for its correct functioning, so that the code
7273 will compile correctly even if the compiler switches are set to suppress
7274 checks. For example, in a program that depends on external names of tagged
7275 types and wants to ensure that the duplicated tag check occurs even if all
7276 run-time checks are suppressed by a compiler switch, the following
7277 configuration pragma will ensure this test is not suppressed:
7278
7279
7280 .. code-block:: ada
7281
7282 pragma Unsuppress (Duplicated_Tag_Check);
7283
7284
7285 This pragma is standard in Ada 2005. It is available in all earlier versions
7286 of Ada as an implementation-defined pragma.
7287
7288 Note that in addition to the checks defined in the Ada RM, GNAT recognizes a
7289 number of implementation-defined check names. See the description of pragma
7290 ``Suppress`` for full details.
7291
7292 .. _Pragma-Unused:
7293
7294 Pragma Unused
7295 =============
7296 .. index:: Warnings, unused
7297
7298 Syntax:
7299
7300
7301 ::
7302
7303 pragma Unused (LOCAL_NAME {, LOCAL_NAME});
7304
7305
7306 This pragma signals that the assignable entities (variables,
7307 ``out`` parameters, and ``in out`` parameters) whose names are listed
7308 deliberately do not get assigned or referenced in the current source unit
7309 after the occurrence of the pragma in the current source unit. This
7310 suppresses warnings about the entities that are unreferenced and/or not
7311 assigned, and, in addition, a warning will be generated if one of these
7312 entities gets assigned or subsequently referenced in the same unit as the
7313 pragma (in the corresponding body or one of its subunits).
7314
7315 This is particularly useful for clearly signaling that a particular
7316 parameter is not modified or referenced, even though the spec suggests
7317 that it might be.
7318
7319 For the variable case, warnings are never given for unreferenced
7320 variables whose name contains one of the substrings
7321 ``DISCARD, DUMMY, IGNORE, JUNK, UNUSED`` in any casing. Such names
7322 are typically to be used in cases where such warnings are expected.
7323 Thus it is never necessary to use ``pragma Unused`` for such
7324 variables, though it is harmless to do so.
7325
7326 Pragma Use_VADS_Size
7327 ====================
7328 .. index:: Size, VADS compatibility
7329
7330 .. index:: Rational profile
7331
7332
7333 Syntax:
7334
7335
7336 .. code-block:: ada
7337
7338 pragma Use_VADS_Size;
7339
7340
7341 This is a configuration pragma. In a unit to which it applies, any use
7342 of the 'Size attribute is automatically interpreted as a use of the
7343 'VADS_Size attribute. Note that this may result in incorrect semantic
7344 processing of valid Ada 95 or Ada 2005 programs. This is intended to aid in
7345 the handling of existing code which depends on the interpretation of Size
7346 as implemented in the VADS compiler. See description of the VADS_Size
7347 attribute for further details.
7348
7349 Pragma Validity_Checks
7350 ======================
7351
7352 Syntax:
7353
7354
7355 .. code-block:: ada
7356
7357 pragma Validity_Checks (string_LITERAL | ALL_CHECKS | On | Off);
7358
7359
7360 This pragma is used in conjunction with compiler switches to control the
7361 built-in validity checking provided by GNAT. The compiler switches, if set
7362 provide an initial setting for the switches, and this pragma may be used
7363 to modify these settings, or the settings may be provided entirely by
7364 the use of the pragma. This pragma can be used anywhere that a pragma
7365 is legal, including use as a configuration pragma (including use in
7366 the :file:`gnat.adc` file).
7367
7368 The form with a string literal specifies which validity options are to be
7369 activated. The validity checks are first set to include only the default
7370 reference manual settings, and then a string of letters in the string
7371 specifies the exact set of options required. The form of this string
7372 is exactly as described for the *-gnatVx* compiler switch (see the
7373 GNAT User's Guide for details). For example the following two
7374 methods can be used to enable validity checking for mode ``in`` and
7375 ``in out`` subprogram parameters:
7376
7377 *
7378
7379 .. code-block:: ada
7380
7381 pragma Validity_Checks ("im");
7382
7383
7384 *
7385
7386 .. code-block:: sh
7387
7388 $ gcc -c -gnatVim ...
7389
7390
7391 The form ALL_CHECKS activates all standard checks (its use is equivalent
7392 to the use of the :switch:`gnatVa` switch).
7393
7394 The forms with ``Off`` and ``On`` can be used to temporarily disable
7395 validity checks as shown in the following example:
7396
7397
7398 .. code-block:: ada
7399
7400 pragma Validity_Checks ("c"); -- validity checks for copies
7401 pragma Validity_Checks (Off); -- turn off validity checks
7402 A := B; -- B will not be validity checked
7403 pragma Validity_Checks (On); -- turn validity checks back on
7404 A := C; -- C will be validity checked
7405
7406 .. _Pragma-Volatile:
7407
7408 Pragma Volatile
7409 ===============
7410
7411 Syntax:
7412
7413
7414 .. code-block:: ada
7415
7416 pragma Volatile (LOCAL_NAME);
7417
7418
7419 This pragma is defined by the Ada Reference Manual, and the GNAT
7420 implementation is fully conformant with this definition. The reason it
7421 is mentioned in this section is that a pragma of the same name was supplied
7422 in some Ada 83 compilers, including DEC Ada 83. The Ada 95 / Ada 2005
7423 implementation of pragma Volatile is upwards compatible with the
7424 implementation in DEC Ada 83.
7425
7426 .. _Pragma-Volatile_Full_Access:
7427
7428 Pragma Volatile_Full_Access
7429 ===========================
7430
7431 Syntax:
7432
7433
7434 .. code-block:: ada
7435
7436 pragma Volatile_Full_Access (LOCAL_NAME);
7437
7438
7439 This is similar in effect to pragma Volatile, except that any reference to the
7440 object is guaranteed to be done only with instructions that read or write all
7441 the bits of the object. Furthermore, if the object is of a composite type,
7442 then any reference to a subcomponent of the object is guaranteed to read
7443 and/or write all the bits of the object.
7444
7445 The intention is that this be suitable for use with memory-mapped I/O devices
7446 on some machines. Note that there are two important respects in which this is
7447 different from ``pragma Atomic``. First a reference to a ``Volatile_Full_Access``
7448 object is not a sequential action in the RM 9.10 sense and, therefore, does
7449 not create a synchronization point. Second, in the case of ``pragma Atomic``,
7450 there is no guarantee that all the bits will be accessed if the reference
7451 is not to the whole object; the compiler is allowed (and generally will)
7452 access only part of the object in this case.
7453
7454 .. _Pragma-Volatile_Function:
7455
7456 Pragma Volatile_Function
7457 ========================
7458
7459 Syntax:
7460
7461 .. code-block:: ada
7462
7463 pragma Volatile_Function [ (static_boolean_EXPRESSION) ];
7464
7465 For the semantics of this pragma, see the entry for aspect ``Volatile_Function``
7466 in the SPARK 2014 Reference Manual, section 7.1.2.
7467
7468 Pragma Warning_As_Error
7469 =======================
7470
7471 Syntax:
7472
7473
7474 .. code-block:: ada
7475
7476 pragma Warning_As_Error (static_string_EXPRESSION);
7477
7478
7479 This configuration pragma allows the programmer to specify a set
7480 of warnings that will be treated as errors. Any warning that
7481 matches the pattern given by the pragma argument will be treated
7482 as an error. This gives more precise control than -gnatwe,
7483 which treats warnings as errors.
7484
7485 This pragma can apply to regular warnings (messages enabled by -gnatw)
7486 and to style warnings (messages that start with "(style)",
7487 enabled by -gnaty).
7488
7489 The pattern may contain asterisks, which match zero or more characters
7490 in the message. For example, you can use ``pragma Warning_As_Error
7491 ("bits of*unused")`` to treat the warning message ``warning: 960 bits of
7492 "a" unused`` as an error. All characters other than asterisk are treated
7493 as literal characters in the match. The match is case insensitive; for
7494 example XYZ matches xyz.
7495
7496 Note that the pattern matches if it occurs anywhere within the warning
7497 message string (it is not necessary to put an asterisk at the start and
7498 the end of the message, since this is implied).
7499
7500 Another possibility for the static_string_EXPRESSION which works whether
7501 or not error tags are enabled (*-gnatw.d*) is to use a single
7502 *-gnatw* tag string, enclosed in brackets,
7503 as shown in the example below, to treat one category of warnings as errors.
7504 Note that if you want to treat multiple categories of warnings as errors,
7505 you can use multiple pragma Warning_As_Error.
7506
7507 The above use of patterns to match the message applies only to warning
7508 messages generated by the front end. This pragma can also be applied to
7509 warnings provided by the back end and mentioned in :ref:`Pragma_Warnings`.
7510 By using a single full *-Wxxx* switch in the pragma, such warnings
7511 can also be treated as errors.
7512
7513 The pragma can appear either in a global configuration pragma file
7514 (e.g. :file:`gnat.adc`), or at the start of a file. Given a global
7515 configuration pragma file containing:
7516
7517
7518 .. code-block:: ada
7519
7520 pragma Warning_As_Error ("[-gnatwj]");
7521
7522
7523 which will treat all obsolescent feature warnings as errors, the
7524 following program compiles as shown (compile options here are
7525 *-gnatwa.d -gnatl -gnatj55*).
7526
7527
7528 ::
7529
7530 1. pragma Warning_As_Error ("*never assigned*");
7531 2. function Warnerr return String is
7532 3. X : Integer;
7533 |
7534 >>> error: variable "X" is never read and
7535 never assigned [-gnatwv] [warning-as-error]
7536
7537 4. Y : Integer;
7538 |
7539 >>> warning: variable "Y" is assigned but
7540 never read [-gnatwu]
7541
7542 5. begin
7543 6. Y := 0;
7544 7. return %ABC%;
7545 |
7546 >>> error: use of "%" is an obsolescent
7547 feature (RM J.2(4)), use """ instead
7548 [-gnatwj] [warning-as-error]
7549
7550 8. end;
7551
7552 8 lines: No errors, 3 warnings (2 treated as errors)
7553
7554
7555 Note that this pragma does not affect the set of warnings issued in
7556 any way, it merely changes the effect of a matching warning if one
7557 is produced as a result of other warnings options. As shown in this
7558 example, if the pragma results in a warning being treated as an error,
7559 the tag is changed from "warning:" to "error:" and the string
7560 "[warning-as-error]" is appended to the end of the message.
7561
7562 .. _Pragma_Warnings:
7563
7564 Pragma Warnings
7565 ===============
7566
7567 Syntax:
7568
7569
7570 .. code-block:: ada
7571
7572 pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
7573
7574 DETAILS ::= On | Off
7575 DETAILS ::= On | Off, local_NAME
7576 DETAILS ::= static_string_EXPRESSION
7577 DETAILS ::= On | Off, static_string_EXPRESSION
7578
7579 TOOL_NAME ::= GNAT | GNATprove
7580
7581 REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
7582
7583 Note: in Ada 83 mode, a string literal may be used in place of a static string
7584 expression (which does not exist in Ada 83).
7585
7586 Note if the second argument of ``DETAILS`` is a ``local_NAME`` then the
7587 second form is always understood. If the intention is to use
7588 the fourth form, then you can write ``NAME & ""`` to force the
7589 interpretation as a *static_string_EXPRESSION*.
7590
7591 Note: if the first argument is a valid ``TOOL_NAME``, it will be interpreted
7592 that way. The use of the ``TOOL_NAME`` argument is relevant only to users
7593 of SPARK and GNATprove, see last part of this section for details.
7594
7595 Normally warnings are enabled, with the output being controlled by
7596 the command line switch. Warnings (``Off``) turns off generation of
7597 warnings until a Warnings (``On``) is encountered or the end of the
7598 current unit. If generation of warnings is turned off using this
7599 pragma, then some or all of the warning messages are suppressed,
7600 regardless of the setting of the command line switches.
7601
7602 The ``Reason`` parameter may optionally appear as the last argument
7603 in any of the forms of this pragma. It is intended purely for the
7604 purposes of documenting the reason for the ``Warnings`` pragma.
7605 The compiler will check that the argument is a static string but
7606 otherwise ignore this argument. Other tools may provide specialized
7607 processing for this string.
7608
7609 The form with a single argument (or two arguments if Reason present),
7610 where the first argument is ``ON`` or ``OFF``
7611 may be used as a configuration pragma.
7612
7613 If the ``LOCAL_NAME`` parameter is present, warnings are suppressed for
7614 the specified entity. This suppression is effective from the point where
7615 it occurs till the end of the extended scope of the variable (similar to
7616 the scope of ``Suppress``). This form cannot be used as a configuration
7617 pragma.
7618
7619 In the case where the first argument is other than ``ON`` or
7620 ``OFF``,
7621 the third form with a single static_string_EXPRESSION argument (and possible
7622 reason) provides more precise
7623 control over which warnings are active. The string is a list of letters
7624 specifying which warnings are to be activated and which deactivated. The
7625 code for these letters is the same as the string used in the command
7626 line switch controlling warnings. For a brief summary, use the gnatmake
7627 command with no arguments, which will generate usage information containing
7628 the list of warnings switches supported. For
7629 full details see the section on ``Warning Message Control`` in the
7630 :title:`GNAT User's Guide`.
7631 This form can also be used as a configuration pragma.
7632
7633 The warnings controlled by the :switch:`-gnatw` switch are generated by the
7634 front end of the compiler. The GCC back end can provide additional warnings
7635 and they are controlled by the :switch:`-W` switch. Such warnings can be
7636 identified by the appearance of a string of the form ``[-W{xxx}]`` in the
7637 message which designates the :switch:`-W{xxx}` switch that controls the message.
7638 The form with a single *static_string_EXPRESSION* argument also works for these
7639 warnings, but the string must be a single full :switch:`-W{xxx}` switch in this
7640 case. The above reference lists a few examples of these additional warnings.
7641
7642 The specified warnings will be in effect until the end of the program
7643 or another pragma ``Warnings`` is encountered. The effect of the pragma is
7644 cumulative. Initially the set of warnings is the standard default set
7645 as possibly modified by compiler switches. Then each pragma Warning
7646 modifies this set of warnings as specified. This form of the pragma may
7647 also be used as a configuration pragma.
7648
7649 The fourth form, with an ``On|Off`` parameter and a string, is used to
7650 control individual messages, based on their text. The string argument
7651 is a pattern that is used to match against the text of individual
7652 warning messages (not including the initial "warning: " tag).
7653
7654 The pattern may contain asterisks, which match zero or more characters in
7655 the message. For example, you can use
7656 ``pragma Warnings (Off, "bits of*unused")`` to suppress the warning
7657 message ``warning: 960 bits of "a" unused``. No other regular
7658 expression notations are permitted. All characters other than asterisk in
7659 these three specific cases are treated as literal characters in the match.
7660 The match is case insensitive, for example XYZ matches xyz.
7661
7662 Note that the pattern matches if it occurs anywhere within the warning
7663 message string (it is not necessary to put an asterisk at the start and
7664 the end of the message, since this is implied).
7665
7666 The above use of patterns to match the message applies only to warning
7667 messages generated by the front end. This form of the pragma with a string
7668 argument can also be used to control warnings provided by the back end and
7669 mentioned above. By using a single full :switch:`-W{xxx}` switch in the pragma,
7670 such warnings can be turned on and off.
7671
7672 There are two ways to use the pragma in this form. The OFF form can be used
7673 as a configuration pragma. The effect is to suppress all warnings (if any)
7674 that match the pattern string throughout the compilation (or match the
7675 -W switch in the back end case).
7676
7677 The second usage is to suppress a warning locally, and in this case, two
7678 pragmas must appear in sequence:
7679
7680
7681 .. code-block:: ada
7682
7683 pragma Warnings (Off, Pattern);
7684 ... code where given warning is to be suppressed
7685 pragma Warnings (On, Pattern);
7686
7687
7688 In this usage, the pattern string must match in the Off and On
7689 pragmas, and (if *-gnatw.w* is given) at least one matching
7690 warning must be suppressed.
7691
7692 Note: if the ON form is not found, then the effect of the OFF form extends
7693 until the end of the file (pragma Warnings is purely textual, so its effect
7694 does not stop at the end of the enclosing scope).
7695
7696 Note: to write a string that will match any warning, use the string
7697 ``"***"``. It will not work to use a single asterisk or two
7698 asterisks since this looks like an operator name. This form with three
7699 asterisks is similar in effect to specifying ``pragma Warnings (Off)`` except (if :switch:`-gnatw.w` is given) that a matching
7700 ``pragma Warnings (On, "***")`` will be required. This can be
7701 helpful in avoiding forgetting to turn warnings back on.
7702
7703 Note: the debug flag :switch:`-gnatd.i` can be
7704 used to cause the compiler to entirely ignore all WARNINGS pragmas. This can
7705 be useful in checking whether obsolete pragmas in existing programs are hiding
7706 real problems.
7707
7708 Note: pragma Warnings does not affect the processing of style messages. See
7709 separate entry for pragma Style_Checks for control of style messages.
7710
7711 Users of the formal verification tool GNATprove for the SPARK subset of Ada may
7712 use the version of the pragma with a ``TOOL_NAME`` parameter.
7713
7714 If present, ``TOOL_NAME`` is the name of a tool, currently either ``GNAT`` for the
7715 compiler or ``GNATprove`` for the formal verification tool. A given tool only
7716 takes into account pragma Warnings that do not specify a tool name, or that
7717 specify the matching tool name. This makes it possible to disable warnings
7718 selectively for each tool, and as a consequence to detect useless pragma
7719 Warnings with switch :switch:`-gnatw.w`.
7720
7721 Pragma Weak_External
7722 ====================
7723
7724 Syntax:
7725
7726
7727 .. code-block:: ada
7728
7729 pragma Weak_External ([Entity =>] LOCAL_NAME);
7730
7731
7732 ``LOCAL_NAME`` must refer to an object that is declared at the library
7733 level. This pragma specifies that the given entity should be marked as a
7734 weak symbol for the linker. It is equivalent to ``__attribute__((weak))``
7735 in GNU C and causes ``LOCAL_NAME`` to be emitted as a weak symbol instead
7736 of a regular symbol, that is to say a symbol that does not have to be
7737 resolved by the linker if used in conjunction with a pragma Import.
7738
7739 When a weak symbol is not resolved by the linker, its address is set to
7740 zero. This is useful in writing interfaces to external modules that may
7741 or may not be linked in the final executable, for example depending on
7742 configuration settings.
7743
7744 If a program references at run time an entity to which this pragma has been
7745 applied, and the corresponding symbol was not resolved at link time, then
7746 the execution of the program is erroneous. It is not erroneous to take the
7747 Address of such an entity, for example to guard potential references,
7748 as shown in the example below.
7749
7750 Some file formats do not support weak symbols so not all target machines
7751 support this pragma.
7752
7753
7754 .. code-block:: ada
7755
7756 -- Example of the use of pragma Weak_External
7757
7758 package External_Module is
7759 key : Integer;
7760 pragma Import (C, key);
7761 pragma Weak_External (key);
7762 function Present return boolean;
7763 end External_Module;
7764
7765 with System; use System;
7766 package body External_Module is
7767 function Present return boolean is
7768 begin
7769 return key'Address /= System.Null_Address;
7770 end Present;
7771 end External_Module;
7772
7773
7774 Pragma Wide_Character_Encoding
7775 ==============================
7776
7777 Syntax:
7778
7779
7780 .. code-block:: ada
7781
7782 pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
7783
7784
7785 This pragma specifies the wide character encoding to be used in program
7786 source text appearing subsequently. It is a configuration pragma, but may
7787 also be used at any point that a pragma is allowed, and it is permissible
7788 to have more than one such pragma in a file, allowing multiple encodings
7789 to appear within the same file.
7790
7791 However, note that the pragma cannot immediately precede the relevant
7792 wide character, because then the previous encoding will still be in
7793 effect, causing "illegal character" errors.
7794
7795 The argument can be an identifier or a character literal. In the identifier
7796 case, it is one of ``HEX``, ``UPPER``, ``SHIFT_JIS``,
7797 ``EUC``, ``UTF8``, or ``BRACKETS``. In the character literal
7798 case it is correspondingly one of the characters :kbd:`h`, :kbd:`u`,
7799 :kbd:`s`, :kbd:`e`, :kbd:`8`, or :kbd:`b`.
7800
7801 Note that when the pragma is used within a file, it affects only the
7802 encoding within that file, and does not affect withed units, specs,
7803 or subunits.