1 \input texinfo @c -*-texinfo-*-
5 @c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
7 @c GNAT DOCUMENTATION o
11 @c Copyright (C) 1995-2002 Free Software Foundation o
14 @c GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). o
16 @c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
18 @setfilename gnat_rm.info
19 @settitle GNAT Reference Manual
20 @setchapternewpage odd
23 @include gcc-common.texi
25 @dircategory GNU Ada tools
27 * GNAT Reference Manual: (gnat_rm). Reference Manual for GNU Ada tools.
31 Copyright @copyright{} 1995-2001, Free Software Foundation
33 Permission is granted to copy, distribute and/or modify this document
34 under the terms of the GNU Free Documentation License, Version 1.2
35 or any later version published by the Free Software Foundation;
36 with the Invariant Sections being ``GNU Free Documentation License'', with the
37 Front-Cover Texts being ``GNAT Reference Manual'', and with no Back-Cover Texts.
38 A copy of the license is included in the section entitled ``GNU
39 Free Documentation License''.
45 @title GNAT Reference Manual
46 @subtitle GNAT, The GNU Ada 95 Compiler
47 @subtitle GNAT Version for GCC @value{version-GCC}
48 @author Ada Core Technologies, Inc.
51 @vskip 0pt plus 1filll
57 @node Top, About This Guide, (dir), (dir)
58 @top GNAT Reference Manual
63 GNAT, The GNU Ada 95 Compiler
65 GNAT Version for GCC @value{version-GCC}
67 Ada Core Technologies, Inc.
74 * Implementation Defined Pragmas::
75 * Implementation Defined Attributes::
76 * Implementation Advice::
77 * Implementation Defined Characteristics::
78 * Intrinsic Subprograms::
79 * Representation Clauses and Pragmas::
80 * Standard Library Routines::
81 * The Implementation of Standard I/O::
83 * Interfacing to Other Languages::
84 * Machine Code Insertions::
85 * GNAT Implementation of Tasking::
86 * Code generation for array aggregates::
87 * Specialized Needs Annexes::
88 * Compatibility Guide::
89 * GNU Free Documentation License::
92 --- The Detailed Node Listing ---
96 * What This Reference Manual Contains::
97 * Related Information::
99 The Implementation of Standard I/O
101 * Standard I/O Packages::
110 * Operations on C Streams::
111 * Interfacing to C Streams::
115 * Ada.Characters.Latin_9 (a-chlat9.ads)::
116 * Ada.Characters.Wide_Latin_1 (a-cwila1.ads)::
117 * Ada.Characters.Wide_Latin_9 (a-cwila9.ads)::
118 * Ada.Command_Line.Remove (a-colire.ads)::
119 * Ada.Direct_IO.C_Streams (a-diocst.ads)::
120 * Ada.Exceptions.Is_Null_Occurrence (a-einuoc.ads)::
121 * Ada.Sequential_IO.C_Streams (a-siocst.ads)::
122 * Ada.Streams.Stream_IO.C_Streams (a-ssicst.ads)::
123 * Ada.Strings.Unbounded.Text_IO (a-suteio.ads)::
124 * Ada.Strings.Wide_Unbounded.Wide_Text_IO (a-swuwti.ads)::
125 * Ada.Text_IO.C_Streams (a-tiocst.ads)::
126 * Ada.Wide_Text_IO.C_Streams (a-wtcstr.ads)::
127 * GNAT.AWK (g-awk.ads)::
128 * GNAT.Bubble_Sort_A (g-busora.ads)::
129 * GNAT.Bubble_Sort_G (g-busorg.ads)::
130 * GNAT.Calendar (g-calend.ads)::
131 * GNAT.Calendar.Time_IO (g-catiio.ads)::
132 * GNAT.Case_Util (g-casuti.ads)::
133 * GNAT.CGI (g-cgi.ads)::
134 * GNAT.CGI.Cookie (g-cgicoo.ads)::
135 * GNAT.CGI.Debug (g-cgideb.ads)::
136 * GNAT.Command_Line (g-comlin.ads)::
137 * GNAT.CRC32 (g-crc32.ads)::
138 * GNAT.Current_Exception (g-curexc.ads)::
139 * GNAT.Debug_Pools (g-debpoo.ads)::
140 * GNAT.Debug_Utilities (g-debuti.ads)::
141 * GNAT.Directory_Operations (g-dirope.ads)::
142 * GNAT.Dynamic_Tables (g-dyntab.ads)::
143 * GNAT.Exception_Traces (g-exctra.ads)::
144 * GNAT.Expect (g-expect.ads)::
145 * GNAT.Float_Control (g-flocon.ads)::
146 * GNAT.Heap_Sort_A (g-hesora.ads)::
147 * GNAT.Heap_Sort_G (g-hesorg.ads)::
148 * GNAT.HTable (g-htable.ads)::
149 * GNAT.IO (g-io.ads)::
150 * GNAT.IO_Aux (g-io_aux.ads)::
151 * GNAT.Lock_Files (g-locfil.ads)::
152 * GNAT.MD5 (g-md5.ads)::
153 * GNAT.Most_Recent_Exception (g-moreex.ads)::
154 * GNAT.OS_Lib (g-os_lib.ads)::
155 * GNAT.Regexp (g-regexp.ads)::
156 * GNAT.Registry (g-regist.ads)::
157 * GNAT.Regpat (g-regpat.ads)::
158 * GNAT.Sockets (g-socket.ads)::
159 * GNAT.Source_Info (g-souinf.ads)::
160 * GNAT.Spell_Checker (g-speche.ads)::
161 * GNAT.Spitbol.Patterns (g-spipat.ads)::
162 * GNAT.Spitbol (g-spitbo.ads)::
163 * GNAT.Spitbol.Table_Boolean (g-sptabo.ads)::
164 * GNAT.Spitbol.Table_Integer (g-sptain.ads)::
165 * GNAT.Spitbol.Table_VString (g-sptavs.ads)::
166 * GNAT.Table (g-table.ads)::
167 * GNAT.Task_Lock (g-tasloc.ads)::
168 * GNAT.Threads (g-thread.ads)::
169 * GNAT.Traceback (g-traceb.ads)::
170 * GNAT.Traceback.Symbolic (g-trasym.ads)::
171 * Interfaces.C.Extensions (i-cexten.ads)::
172 * Interfaces.C.Streams (i-cstrea.ads)::
173 * Interfaces.CPP (i-cpp.ads)::
174 * Interfaces.Os2lib (i-os2lib.ads)::
175 * Interfaces.Os2lib.Errors (i-os2err.ads)::
176 * Interfaces.Os2lib.Synchronization (i-os2syn.ads)::
177 * Interfaces.Os2lib.Threads (i-os2thr.ads)::
178 * Interfaces.Packed_Decimal (i-pacdec.ads)::
179 * Interfaces.VxWorks (i-vxwork.ads)::
180 * Interfaces.VxWorks.IO (i-vxwoio.ads)::
181 * System.Address_Image (s-addima.ads)::
182 * System.Assertions (s-assert.ads)::
183 * System.Partition_Interface (s-parint.ads)::
184 * System.Task_Info (s-tasinf.ads)::
185 * System.Wch_Cnv (s-wchcnv.ads)::
186 * System.Wch_Con (s-wchcon.ads)::
190 * Text_IO Stream Pointer Positioning::
191 * Text_IO Reading and Writing Non-Regular Files::
193 * Treating Text_IO Files as Streams::
194 * Text_IO Extensions::
195 * Text_IO Facilities for Unbounded Strings::
199 * Wide_Text_IO Stream Pointer Positioning::
200 * Wide_Text_IO Reading and Writing Non-Regular Files::
202 Interfacing to Other Languages
205 * Interfacing to C++::
206 * Interfacing to COBOL::
207 * Interfacing to Fortran::
208 * Interfacing to non-GNAT Ada code::
210 GNAT Implementation of Tasking
212 * Mapping Ada Tasks onto the Underlying Kernel Threads::
213 * Ensuring Compliance with the Real-Time Annex::
218 @node About This Guide
219 @unnumbered About This Guide
222 This manual contains useful information in writing programs using the
223 GNAT compiler. It includes information on implementation dependent
224 characteristics of GNAT, including all the information required by Annex
227 Ada 95 is designed to be highly portable,and guarantees that, for most
228 programs, Ada 95 compilers behave in exactly the same manner on
229 different machines. However, since Ada 95 is designed to be used in a
230 wide variety of applications, it also contains a number of system
231 dependent features to Functbe used in interfacing to the external world.
233 @c Maybe put the following in platform-specific section
236 This reference manual discusses how these features are implemented for
237 use in ProDev Ada running on the IRIX 5.3 or greater operating systems.
240 @cindex Implementation-dependent features
242 Note: Any program that makes use of implementation-dependent features
243 may be non-portable. You should follow good programming practice and
244 isolate and clearly document any sections of your program that make use
245 of these features in a non-portable manner.
248 * What This Reference Manual Contains::
250 * Related Information::
253 @node What This Reference Manual Contains
254 @unnumberedsec What This Reference Manual Contains
256 This reference manual contains the following chapters:
260 @ref{Implementation Defined Pragmas} lists GNAT implementation-dependent
261 pragmas, which can be used to extend and enhance the functionality of the
265 @ref{Implementation Defined Attributes} lists GNAT
266 implementation-dependent attributes which can be used to extend and
267 enhance the functionality of the compiler.
270 @ref{Implementation Advice} provides information on generally
271 desirable behavior which are not requirements that all compilers must
272 follow since it cannot be provided on all systems, or which may be
273 undesirable on some systems.
276 @ref{Implementation Defined Characteristics} provides a guide to
277 minimizing implementation dependent features.
280 @ref{Intrinsic Subprograms} describes the intrinsic subprograms
281 implemented by GNAT, and how they can be imported into user
282 application programs.
285 @ref{Representation Clauses and Pragmas} describes in detail the
286 way that GNAT represents data, and in particular the exact set
287 of representation clauses and pragmas that is accepted.
290 @ref{Standard Library Routines} provides a listing of packages and a
291 brief description of the functionality that is provided by Ada's
292 extensive set of standard library routines as implemented by GNAT@.
295 @ref{The Implementation of Standard I/O} details how the GNAT
296 implementation of the input-output facilities.
299 @ref{Interfacing to Other Languages} describes how programs
300 written in Ada using GNAT can be interfaced to other programming
304 @ref{Specialized Needs Annexes} describes the GNAT implementation of all
305 of the special needs annexes.
308 @ref{Compatibility Guide} includes sections on compatibility of GNAT with
309 other Ada 83 and Ada 95 compilation systems, to assist in porting code
310 from other environments.
313 @cindex Ada 95 ISO/ANSI Standard
314 This reference manual assumes that you are familiar with Ada 95
315 language, as described in the International Standard
316 ANSI/ISO/IEC-8652:1995, Jan 1995.
319 @unnumberedsec Conventions
320 @cindex Conventions, typographical
321 @cindex Typographical conventions
324 Following are examples of the typographical and graphic conventions used
329 @code{Functions}, @code{utility program names}, @code{standard names},
336 @file{File Names}, @samp{button names}, and @samp{field names}.
345 [optional information or parameters]
348 Examples are described by text
350 and then shown this way.
355 Commands that are entered by the user are preceded in this manual by the
356 characters @samp{$ } (dollar sign followed by space). If your system uses this
357 sequence as a prompt, then the commands will appear exactly as you see them
358 in the manual. If your system uses some other prompt, then the command will
359 appear with the @samp{$} replaced by whatever prompt character you are using.
361 @node Related Information
362 @unnumberedsec Related Information
363 See the following documents for further information on GNAT:
367 @cite{GNAT User's Guide}, which provides information on how to use
368 the GNAT compiler system.
371 @cite{Ada 95 Reference Manual}, which contains all reference
372 material for the Ada 95 programming language.
375 @cite{Ada 95 Annotated Reference Manual}, which is an annotated version
376 of the standard reference manual cited above. The annotations describe
377 detailed aspects of the design decision, and in particular contain useful
378 sections on Ada 83 compatibility.
381 @cite{DEC Ada, Technical Overview and Comparison on DIGITAL Platforms},
382 which contains specific information on compatibility between GNAT and
386 @cite{DEC Ada, Language Reference Manual, part number AA-PYZAB-TK} which
387 describes in detail the pragmas and attributes provided by the DEC Ada 83
392 @node Implementation Defined Pragmas
393 @chapter Implementation Defined Pragmas
396 Ada 95 defines a set of pragmas that can be used to supply additional
397 information to the compiler. These language defined pragmas are
398 implemented in GNAT and work as described in the Ada 95 Reference
401 In addition, Ada 95 allows implementations to define additional pragmas
402 whose meaning is defined by the implementation. GNAT provides a number
403 of these implementation-dependent pragmas which can be used to extend
404 and enhance the functionality of the compiler. This section of the GNAT
405 Reference Manual describes these additional pragmas.
407 Note that any program using these pragmas may not be portable to other
408 compilers (although GNAT implements this set of pragmas on all
409 platforms). Therefore if portability to other compilers is an important
410 consideration, the use of these pragmas should be minimized.
415 @cindex Deferring aborts
416 @item pragma Abort_Defer
425 This pragma must appear at the start of the statement sequence of a
426 handled sequence of statements (right after the @code{begin}). It has
427 the effect of deferring aborts for the sequence of statements (but not
428 for the declarations or handlers, if any, associated with this statement
441 A configuration pragma that establishes Ada 83 mode for the unit to
442 which it applies, regardless of the mode set by the command line
443 switches. In Ada 83 mode, GNAT attempts to be as compatible with
444 the syntax and semantics of Ada 83, as defined in the original Ada
445 83 Reference Manual as possible. In particular, the new Ada 95
446 keywords are not recognized, optional package bodies are allowed,
447 and generics may name types with unknown discriminants without using
448 the @code{(<>)} notation. In addition, some but not all of the additional
449 restrictions of Ada 83 are enforced.
451 Ada 83 mode is intended for two purposes. Firstly, it allows existing
452 legacy Ada 83 code to be compiled and adapted to GNAT with less effort.
453 Secondly, it aids in keeping code backwards compatible with Ada 83.
454 However, there is no guarantee that code that is processed correctly
455 by GNAT in Ada 83 mode will in fact compile and execute with an Ada
456 83 compiler, since GNAT does not enforce all the additional checks
469 A configuration pragma that establishes Ada 95 mode for the unit to which
470 it applies, regardless of the mode set by the command line switches.
471 This mode is set automatically for the @code{Ada} and @code{System}
472 packages and their children, so you need not specify it in these
473 contexts. This pragma is useful when writing a reusable component that
474 itself uses Ada 95 features, but which is intended to be usable from
475 either Ada 83 or Ada 95 programs.
478 @item pragma Annotate
483 pragma Annotate (IDENTIFIER @{, ARG@});
485 ARG ::= NAME | EXPRESSION
489 This pragma is used to annotate programs. @var{identifier} identifies
490 the type of annotation. GNAT verifies this is an identifier, but does
491 not otherwise analyze it. The @var{arg} argument
492 can be either a string literal or an
493 expression. String literals are assumed to be of type
494 @code{Standard.String}. Names of entities are simply analyzed as entity
495 names. All other expressions are analyzed as expressions, and must be
498 The analyzed pragma is retained in the tree, but not otherwise processed
499 by any part of the GNAT compiler. This pragma is intended for use by
500 external tools, including ASIS@.
510 [, static_string_EXPRESSION])
514 The effect of this pragma depends on whether the corresponding command
515 line switch is set to activate assertions. The pragma expands into code
516 equivalent to the following:
519 if assertions-enabled then
520 if not boolean_EXPRESSION then
521 System.Assertions.Raise_Assert_Failure
528 The string argument, if given, is the message that will be associated
529 with the exception occurrence if the exception is raised. If no second
530 argument is given, the default message is @samp{@var{file}:@var{nnn}},
531 where @var{file} is the name of the source file containing the assert,
532 and @var{nnn} is the line number of the assert. A pragma is not a
533 statement, so if a statement sequence contains nothing but a pragma
534 assert, then a null statement is required in addition, as in:
539 pragma Assert (K > 3, "Bad value for K");
545 Note that, as with the @code{if} statement to which it is equivalent, the
546 type of the expression is either @code{Standard.Boolean}, or any type derived
547 from this standard type.
549 If assertions are disabled (switch @code{-gnata} not used), then there
550 is no effect (and in particular, any side effects from the expression
551 are suppressed). More precisely it is not quite true that the pragma
552 has no effect, since the expression is analyzed, and may cause types
553 to be frozen if they are mentioned here for the first time.
555 If assertions are enabled, then the given expression is tested, and if
556 it is @code{False} then @code{System.Assertions.Raise_Assert_Failure} is called
557 which results in the raising of @code{Assert_Failure} with the given message.
559 If the boolean expression has side effects, these side effects will turn
560 on and off with the setting of the assertions mode, resulting in
561 assertions that have an effect on the program. You should generally
562 avoid side effects in the expression arguments of this pragma. However,
563 the expressions are analyzed for semantic correctness whether or not
564 assertions are enabled, so turning assertions on and off cannot affect
565 the legality of a program.
569 @item pragma Ast_Entry
574 pragma AST_Entry (entry_IDENTIFIER);
578 This pragma is implemented only in the OpenVMS implementation of GNAT@. The
579 argument is the simple name of a single entry; at most one @code{AST_Entry}
580 pragma is allowed for any given entry. This pragma must be used in
581 conjunction with the @code{AST_Entry} attribute, and is only allowed after
582 the entry declaration and in the same task type specification or single task
583 as the entry to which it applies. This pragma specifies that the given entry
584 may be used to handle an OpenVMS asynchronous system trap (@code{AST})
585 resulting from an OpenVMS system service call. The pragma does not affect
586 normal use of the entry. For further details on this pragma, see the
587 DEC Ada Language Reference Manual, section 9.12a.
589 @cindex Passing by copy
590 @findex C_Pass_By_Copy
591 @item pragma C_Pass_By_Copy
596 pragma C_Pass_By_Copy
597 ([Max_Size =>] static_integer_EXPRESSION);
601 Normally the default mechanism for passing C convention records to C
602 convention subprograms is to pass them by reference, as suggested by RM
603 B.3(69). Use the configuration pragma @code{C_Pass_By_Copy} to change
604 this default, by requiring that record formal parameters be passed by
605 copy if all of the following conditions are met:
609 The size of the record type does not exceed@*@var{static_integer_expression}.
611 The record type has @code{Convention C}.
613 The formal parameter has this record type, and the subprogram has a
614 foreign (non-Ada) convention.
618 If these conditions are met the argument is passed by copy, i.e.@: in a
619 manner consistent with what C expects if the corresponding formal in the
620 C prototype is a struct (rather than a pointer to a struct).
622 You can also pass records by copy by specifying the convention
623 @code{C_Pass_By_Copy} for the record type, or by using the extended
624 @code{Import} and @code{Export} pragmas, which allow specification of
625 passing mechanisms on a parameter by parameter basis.
633 pragma Comment (static_string_EXPRESSION);
637 This is almost identical in effect to pragma @code{Ident}. It allows the
638 placement of a comment into the object file and hence into the
639 executable file if the operating system permits such usage. The
640 difference is that @code{Comment}, unlike @code{Ident}, has no limit on the
641 length of the string argument, and no limitations on placement
642 of the pragma (it can be placed anywhere in the main source unit).
644 @findex Common_Object
645 @item pragma Common_Object
650 pragma Common_Object (
651 [Internal =>] LOCAL_NAME,
652 [, [External =>] EXTERNAL_SYMBOL]
653 [, [Size =>] EXTERNAL_SYMBOL] )
657 | static_string_EXPRESSION
661 This pragma enables the shared use of variables stored in overlaid
662 linker areas corresponding to the use of @code{COMMON}
663 in Fortran. The single
664 object @var{local_name} is assigned to the area designated by
665 the @var{External} argument.
666 You may define a record to correspond to a series
667 of fields. The @var{size} argument
668 is syntax checked in GNAT, but otherwise ignored.
670 @code{Common_Object} is not supported on all platforms. If no
671 support is available, then the code generator will issue a message
672 indicating that the necessary attribute for implementation of this
673 pragma is not available.
675 @findex Complex_Representation
676 @item pragma Complex_Representation
681 pragma Complex_Representation
682 ([Entity =>] LOCAL_NAME);
686 The @var{Entity} argument must be the name of a record type which has
687 two fields of the same floating-point type. The effect of this pragma is
688 to force gcc to use the special internal complex representation form for
689 this record, which may be more efficient. Note that this may result in
690 the code for this type not conforming to standard ABI (application
691 binary interface) requirements for the handling of record types. For
692 example, in some environments, there is a requirement for passing
693 records by pointer, and the use of this pragma may result in passing
694 this type in floating-point registers.
696 @cindex Alignments of components
697 @findex Component_Alignment
698 @item pragma Component_Alignment
703 pragma Component_Alignment (
704 [Form =>] ALIGNMENT_CHOICE
705 [, [Name =>] type_LOCAL_NAME]);
715 Specifies the alignment of components in array or record types.
716 The meaning of the @var{Form} argument is as follows:
719 @findex Component_Size
721 Aligns scalar components and subcomponents of the array or record type
722 on boundaries appropriate to their inherent size (naturally
723 aligned). For example, 1-byte components are aligned on byte boundaries,
724 2-byte integer components are aligned on 2-byte boundaries, 4-byte
725 integer components are aligned on 4-byte boundaries and so on. These
726 alignment rules correspond to the normal rules for C compilers on all
727 machines except the VAX@.
729 @findex Component_Size_4
730 @item Component_Size_4
731 Naturally aligns components with a size of four or fewer
732 bytes. Components that are larger than 4 bytes are placed on the next
737 Specifies that array or record components are byte aligned, i.e.@:
738 aligned on boundaries determined by the value of the constant
739 @code{System.Storage_Unit}.
743 Specifies that array or record components are aligned on default
744 boundaries, appropriate to the underlying hardware or operating system or
745 both. For OpenVMS VAX systems, the @code{Default} choice is the same as
746 the @code{Storage_Unit} choice (byte alignment). For all other systems,
747 the @code{Default} choice is the same as @code{Component_Size} (natural
751 If the @code{Name} parameter is present, @var{type_local_name} must
752 refer to a local record or array type, and the specified alignment
753 choice applies to the specified type. The use of
754 @code{Component_Alignment} together with a pragma @code{Pack} causes the
755 @code{Component_Alignment} pragma to be ignored. The use of
756 @code{Component_Alignment} together with a record representation clause
757 is only effective for fields not specified by the representation clause.
759 If the @code{Name} parameter is absent, the pragma can be used as either
760 a configuration pragma, in which case it applies to one or more units in
761 accordance with the normal rules for configuration pragmas, or it can be
762 used within a declarative part, in which case it applies to types that
763 are declared within this declarative part, or within any nested scope
764 within this declarative part. In either case it specifies the alignment
765 to be applied to any record or array type which has otherwise standard
768 If the alignment for a record or array type is not specified (using
769 pragma @code{Pack}, pragma @code{Component_Alignment}, or a record rep
770 clause), the GNAT uses the default alignment as described previously.
772 @findex Convention_Identifier
773 @cindex Conventions, synonyms
774 @item pragma Convention_Identifier
779 pragma Convention_Identifier (
780 [Name =>] IDENTIFIER,
781 [Convention =>] convention_IDENTIFIER);
785 This pragma provides a mechanism for supplying synonyms for existing
786 convention identifiers. The @code{Name} identifier can subsequently
787 be used as a synonym for the given convention in other pragmas (including
788 for example pragma @code{Import} or another @code{Convention_Identifier}
789 pragma). As an example of the use of this, suppose you had legacy code
790 which used Fortran77 as the identifier for Fortran. Then the pragma:
793 pragma Convention_Indentifier (Fortran77, Fortran);
797 would allow the use of the convention identifier @code{Fortran77} in
798 subsequent code, avoiding the need to modify the sources. As another
799 example, you could use this to parametrize convention requirements
800 according to systems. Suppose you needed to use @code{Stdcall} on
801 windows systems, and @code{C} on some other system, then you could
802 define a convention identifier @code{Library} and use a single
803 @code{Convention_Identifier} pragma to specify which convention
804 would be used system-wide.
807 @cindex Interfacing with C++
808 @item pragma CPP_Class
813 pragma CPP_Class ([Entity =>] LOCAL_NAME);
817 The argument denotes an entity in the current declarative region
818 that is declared as a tagged or untagged record type. It indicates that
819 the type corresponds to an externally declared C++ class type, and is to
820 be laid out the same way that C++ would lay out the type.
822 If (and only if) the type is tagged, at least one component in the
823 record must be of type @code{Interfaces.CPP.Vtable_Ptr}, corresponding
824 to the C++ Vtable (or Vtables in the case of multiple inheritance) used
827 Types for which @code{CPP_Class} is specified do not have assignment or
828 equality operators defined (such operations can be imported or declared
829 as subprograms as required). Initialization is allowed only by
830 constructor functions (see pragma @code{CPP_Constructor}).
832 Pragma @code{CPP_Class} is intended primarily for automatic generation
833 using an automatic binding generator tool.
834 See @ref{Interfacing to C++} for related information.
836 @cindex Interfacing with C++
837 @findex CPP_Constructor
838 @item pragma CPP_Constructor
843 pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
847 This pragma identifies an imported function (imported in the usual way
848 with pragma @code{Import}) as corresponding to a C++
849 constructor. The argument is a name that must have been
850 previously mentioned in a pragma @code{Import}
851 with @code{Convention} = @code{CPP}, and must be of one of the following
856 @code{function @var{Fname} return @var{T}'Class}
859 @code{function @var{Fname} (@dots{}) return @var{T}'Class}
863 where @var{T} is a tagged type to which the pragma @code{CPP_Class} applies.
865 The first form is the default constructor, used when an object of type
866 @var{T} is created on the Ada side with no explicit constructor. Other
867 constructors (including the copy constructor, which is simply a special
868 case of the second form in which the one and only argument is of type
869 @var{T}), can only appear in two contexts:
873 On the right side of an initialization of an object of type @var{T}.
875 In an extension aggregate for an object of a type derived from @var{T}.
878 Although the constructor is described as a function that returns a value
879 on the Ada side, it is typically a procedure with an extra implicit
880 argument (the object being initialized) at the implementation
881 level. GNAT issues the appropriate call, whatever it is, to get the
882 object properly initialized.
884 In the case of derived objects, you may use one of two possible forms
885 for declaring and creating an object:
888 @item @code{New_Object : Derived_T}
889 @item @code{New_Object : Derived_T := (@var{constructor-function-call with} @dots{})}
892 In the first case the default constructor is called and extension fields
893 if any are initialized according to the default initialization
894 expressions in the Ada declaration. In the second case, the given
895 constructor is called and the extension aggregate indicates the explicit
896 values of the extension fields.
898 If no constructors are imported, it is impossible to create any objects
899 on the Ada side. If no default constructor is imported, only the
900 initialization forms using an explicit call to a constructor are
903 Pragma @code{CPP_Constructor} is intended primarily for automatic generation
904 using an automatic binding generator tool.
905 See @ref{Interfacing to C++} for more related information.
907 @cindex Interfacing to C++
909 @item pragma CPP_Virtual
916 [, [Vtable_Ptr =>] vtable_ENTITY,]
917 [, [Position =>] static_integer_EXPRESSION])
920 This pragma serves the same function as pragma @code{Import} in that
921 case of a virtual function imported from C++. The @var{Entity} argument
923 primitive subprogram of a tagged type to which pragma @code{CPP_Class}
924 applies. The @var{Vtable_Ptr} argument specifies
925 the Vtable_Ptr component which contains the
926 entry for this virtual function. The @var{Position} argument
927 is the sequential number
928 counting virtual functions for this Vtable starting at 1.
930 The @code{Vtable_Ptr} and @code{Position} arguments may be omitted if
931 there is one Vtable_Ptr present (single inheritance case) and all
932 virtual functions are imported. In that case the compiler can deduce both
935 No @code{External_Name} or @code{Link_Name} arguments are required for a
936 virtual function, since it is always accessed indirectly via the
937 appropriate Vtable entry.
939 Pragma @code{CPP_Virtual} is intended primarily for automatic generation
940 using an automatic binding generator tool.
941 See @ref{Interfacing to C++} for related information.
943 @cindex Interfacing with C++
945 @item pragma CPP_Vtable
952 [Vtable_Ptr =>] vtable_ENTITY,
953 [Entry_Count =>] static_integer_EXPRESSION);
957 Given a record to which the pragma @code{CPP_Class} applies,
958 this pragma can be specified for each component of type
959 @code{CPP.Interfaces.Vtable_Ptr}.
960 @var{Entity} is the tagged type, @var{Vtable_Ptr}
961 is the record field of type @code{Vtable_Ptr}, and @var{Entry_Count} is
962 the number of virtual functions on the C++ side. Not all of these
963 functions need to be imported on the Ada side.
965 You may omit the @code{CPP_Vtable} pragma if there is only one
966 @code{Vtable_Ptr} component in the record and all virtual functions are
967 imported on the Ada side (the default value for the entry count in this
968 case is simply the total number of virtual functions).
970 Pragma @code{CPP_Vtable} is intended primarily for automatic generation
971 using an automatic binding generator tool.
972 See @ref{Interfacing to C++} for related information.
980 pragma Debug (PROCEDURE_CALL_WITHOUT_SEMICOLON);
982 PROCEDURE_CALL_WITHOUT_SEMICOLON ::=
984 | PROCEDURE_PREFIX ACTUAL_PARAMETER_PART
988 The argument has the syntactic form of an expression, meeting the
989 syntactic requirements for pragmas.
991 If assertions are not enabled on the command line, this pragma has no
992 effect. If asserts are enabled, the semantics of the pragma is exactly
993 equivalent to the procedure call statement corresponding to the argument
994 with a terminating semicolon. Pragmas are permitted in sequences of
995 declarations, so you can use pragma @code{Debug} to intersperse calls to
996 debug procedures in the middle of declarations.
998 @cindex Elaboration control
999 @findex Elaboration_Checks
1000 @item pragma Elaboration_Checks
1005 pragma Elaboration_Checks (RM | Static);
1009 This is a configuration pragma that provides control over the
1010 elaboration model used by the compilation affected by the
1011 pragma. If the parameter is RM, then the dynamic elaboration
1012 model described in the Ada Reference Manual is used, as though
1013 the @code{-gnatE} switch had been specified on the command
1014 line. If the parameter is Static, then the default GNAT static
1015 model is used. This configuration pragma overrides the setting
1016 of the command line. For full details on the elaboration models
1017 used by the GNAT compiler, see section ``Elaboration Order
1018 Handling in GNAT'' in the @cite{GNAT User's Guide}.
1020 @cindex Elimination of unused subprograms
1022 @item pragma Eliminate
1028 [Unit_Name =>] IDENTIFIER |
1029 SELECTED_COMPONENT);
1032 [Unit_Name =>] IDENTIFIER |
1034 [Entity =>] IDENTIFIER |
1035 SELECTED_COMPONENT |
1037 [,[Parameter_Types =>] PARAMETER_TYPES]
1038 [,[Result_Type =>] result_SUBTYPE_NAME]
1039 [,[Homonym_Number =>] INTEGER_LITERAL]);
1041 PARAMETER_TYPES ::= (SUBTYPE_NAME @{, SUBTYPE_NAME@})
1042 SUBTYPE_NAME ::= STRING_LITERAL
1046 This pragma indicates that the given entity is not used outside the
1047 compilation unit it is defined in. The entity may be either a subprogram
1050 If the entity to be eliminated is a library level subprogram, then
1051 the first form of pragma @code{Eliminate} is used with only a single argument.
1052 In this form, the @code{Unit_Name} argument specifies the name of the
1053 library level unit to be eliminated.
1055 In all other cases, both @code{Unit_Name} and @code{Entity} arguments
1056 are required. item is an entity of a library package, then the first
1057 argument specifies the unit name, and the second argument specifies
1058 the particular entity. If the second argument is in string form, it must
1059 correspond to the internal manner in which GNAT stores entity names (see
1060 compilation unit Namet in the compiler sources for details).
1062 The remaining parameters are optionally used to distinguish
1063 between overloaded subprograms. There are two ways of doing this.
1065 Use @code{Parameter_Types} and @code{Result_Type} to specify the
1066 profile of the subprogram to be eliminated in a manner similar to that
1068 the extended @code{Import} and @code{Export} pragmas, except that the
1069 subtype names are always given as string literals, again corresponding
1070 to the internal manner in which GNAT stores entity names.
1072 Alternatively, the @code{Homonym_Number} parameter is used to specify
1073 which overloaded alternative is to be eliminated. A value of 1 indicates
1074 the first subprogram (in lexical order), 2 indicates the second etc.
1076 The effect of the pragma is to allow the compiler to eliminate
1077 the code or data associated with the named entity. Any reference to
1078 an eliminated entity outside the compilation unit it is defined in,
1079 causes a compile time or link time error.
1081 The parameters of this pragma may be given in any order, as long as
1082 the usual rules for use of named parameters and position parameters
1085 The intention of pragma @code{Eliminate} is to allow a program to be compiled
1086 in a system independent manner, with unused entities eliminated, without
1087 the requirement of modifying the source text. Normally the required set
1088 of @code{Eliminate} pragmas is constructed automatically using the gnatelim tool.
1089 Elimination of unused entities local to a compilation unit is automatic,
1090 without requiring the use of pragma @code{Eliminate}.
1092 Note that the reason this pragma takes string literals where names might
1093 be expected is that a pragma @code{Eliminate} can appear in a context where the
1094 relevant names are not visible.
1097 @findex Export_Exception
1098 @item pragma Export_Exception
1103 pragma Export_Exception (
1104 [Internal =>] LOCAL_NAME,
1105 [, [External =>] EXTERNAL_SYMBOL,]
1106 [, [Form =>] Ada | VMS]
1107 [, [Code =>] static_integer_EXPRESSION]);
1111 | static_string_EXPRESSION
1115 This pragma is implemented only in the OpenVMS implementation of GNAT@. It
1116 causes the specified exception to be propagated outside of the Ada program,
1117 so that it can be handled by programs written in other OpenVMS languages.
1118 This pragma establishes an external name for an Ada exception and makes the
1119 name available to the OpenVMS Linker as a global symbol. For further details
1120 on this pragma, see the
1121 DEC Ada Language Reference Manual, section 13.9a3.2.
1123 @cindex Argument passing mechanisms
1124 @findex Export_Function
1125 @item pragma Export_Function @dots{}
1131 pragma Export_Function (
1132 [Internal =>] LOCAL_NAME,
1133 [, [External =>] EXTERNAL_SYMBOL]
1134 [, [Parameter_Types =>] PARAMETER_TYPES]
1135 [, [Result_Type =>] result_SUBTYPE_MARK]
1136 [, [Mechanism =>] MECHANISM]
1137 [, [Result_Mechanism =>] MECHANISM_NAME]);
1141 | static_string_EXPRESSION
1145 | SUBTYPE_MARK @{, SUBTYPE_MARK@}
1149 | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
1151 MECHANISM_ASSOCIATION ::=
1152 [formal_parameter_NAME =>] MECHANISM_NAME
1157 | Descriptor [([Class =>] CLASS_NAME)]
1159 CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
1162 Use this pragma to make a function externally callable and optionally
1163 provide information on mechanisms to be used for passing parameter and
1164 result values. We recommend, for the purposes of improving portability,
1165 this pragma always be used in conjunction with a separate pragma
1166 @code{Export}, which must precede the pragma @code{Export_Function}.
1167 GNAT does not require a separate pragma @code{Export}, but if none is
1168 present, @code{Convention Ada} is assumed, which is usually
1169 not what is wanted, so it is usually appropriate to use this
1170 pragma in conjunction with a @code{Export} or @code{Convention}
1171 pragma that specifies the desired foreign convention.
1172 Pragma @code{Export_Function}
1173 (and @code{Export}, if present) must appear in the same declarative
1174 region as the function to which they apply.
1176 @var{internal_name} must uniquely designate the function to which the
1177 pragma applies. If more than one function name exists of this name in
1178 the declarative part you must use the @code{Parameter_Types} and
1179 @code{Result_Type} parameters is mandatory to achieve the required
1180 unique designation. @var{subtype_ mark}s in these parameters must
1181 exactly match the subtypes in the corresponding function specification,
1182 using positional notation to match parameters with subtype marks.
1184 @cindex Passing by descriptor
1185 Passing by descriptor is supported only on the OpenVMS ports of GNAT@.
1187 @findex Export_Object
1188 @item pragma Export_Object @dots{}
1193 pragma Export_Object
1194 [Internal =>] LOCAL_NAME,
1195 [, [External =>] EXTERNAL_SYMBOL]
1196 [, [Size =>] EXTERNAL_SYMBOL]
1200 | static_string_EXPRESSION
1203 This pragma designates an object as exported, and apart from the
1204 extended rules for external symbols, is identical in effect to the use of
1205 the normal @code{Export} pragma applied to an object. You may use a
1206 separate Export pragma (and you probably should from the point of view
1207 of portability), but it is not required. @var{Size} is syntax checked,
1208 but otherwise ignored by GNAT@.
1210 @findex Export_Procedure
1211 @item pragma Export_Procedure @dots{}
1216 pragma Export_Procedure (
1217 [Internal =>] LOCAL_NAME
1218 [, [External =>] EXTERNAL_SYMBOL]
1219 [, [Parameter_Types =>] PARAMETER_TYPES]
1220 [, [Mechanism =>] MECHANISM]);
1224 | static_string_EXPRESSION
1228 | SUBTYPE_MARK @{, SUBTYPE_MARK@}
1232 | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
1234 MECHANISM_ASSOCIATION ::=
1235 [formal_parameter_NAME =>] MECHANISM_NAME
1240 | Descriptor [([Class =>] CLASS_NAME)]
1242 CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
1246 This pragma is identical to @code{Export_Function} except that it
1247 applies to a procedure rather than a function and the parameters
1248 @code{Result_Type} and @code{Result_Mechanism} are not permitted.
1249 GNAT does not require a separate pragma @code{Export}, but if none is
1250 present, @code{Convention Ada} is assumed, which is usually
1251 not what is wanted, so it is usually appropriate to use this
1252 pragma in conjunction with a @code{Export} or @code{Convention}
1253 pragma that specifies the desired foreign convention.
1255 @findex Export_Valued_Procedure
1256 @item pragma Export_Valued_Procedure
1261 pragma Export_Valued_Procedure (
1262 [Internal =>] LOCAL_NAME
1263 [, [External =>] EXTERNAL_SYMBOL]
1264 [, [Parameter_Types =>] PARAMETER_TYPES]
1265 [, [Mechanism =>] MECHANISM]);
1269 | static_string_EXPRESSION
1273 | SUBTYPE_MARK @{, SUBTYPE_MARK@}
1277 | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
1279 MECHANISM_ASSOCIATION ::=
1280 [formal_parameter_NAME =>] MECHANISM_NAME
1285 | Descriptor [([Class =>] CLASS_NAME)]
1287 CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
1290 This pragma is identical to @code{Export_Procedure} except that the
1291 first parameter of @var{local_name}, which must be present, must be of
1292 mode @code{OUT}, and externally the subprogram is treated as a function
1293 with this parameter as the result of the function. GNAT provides for
1294 this capability to allow the use of @code{OUT} and @code{IN OUT}
1295 parameters in interfacing to external functions (which are not permitted
1297 GNAT does not require a separate pragma @code{Export}, but if none is
1298 present, @code{Convention Ada} is assumed, which is almost certainly
1299 not what is wanted since the whole point of this pragma is to interface
1300 with foreign language functions, so it is usually appropriate to use this
1301 pragma in conjunction with a @code{Export} or @code{Convention}
1302 pragma that specifies the desired foreign convention.
1304 @cindex @code{system}, extending
1306 @findex Extend_System
1307 @item pragma Extend_System
1312 pragma Extend_System ([Name =>] IDENTIFIER);
1316 This pragma is used to provide backwards compatibility with other
1317 implementations that extend the facilities of package @code{System}. In
1318 GNAT, @code{System} contains only the definitions that are present in
1319 the Ada 95 RM@. However, other implementations, notably the DEC Ada 83
1320 implementation, provide many extensions to package @code{System}.
1322 For each such implementation accommodated by this pragma, GNAT provides a
1323 package @code{Aux_@var{xxx}}, e.g.@: @code{Aux_DEC} for the DEC Ada 83
1324 implementation, which provides the required additional definitions. You
1325 can use this package in two ways. You can @code{with} it in the normal
1326 way and access entities either by selection or using a @code{use}
1327 clause. In this case no special processing is required.
1329 However, if existing code contains references such as
1330 @code{System.@var{xxx}} where @var{xxx} is an entity in the extended
1331 definitions provided in package @code{System}, you may use this pragma
1332 to extend visibility in @code{System} in a non-standard way that
1333 provides greater compatibility with the existing code. Pragma
1334 @code{Extend_System} is a configuration pragma whose single argument is
1335 the name of the package containing the extended definition
1336 (e.g.@: @code{Aux_DEC} for the DEC Ada case). A unit compiled under
1337 control of this pragma will be processed using special visibility
1338 processing that looks in package @code{System.Aux_@var{xxx}} where
1339 @code{Aux_@var{xxx}} is the pragma argument for any entity referenced in
1340 package @code{System}, but not found in package @code{System}.
1342 You can use this pragma either to access a predefined @code{System}
1343 extension supplied with the compiler, for example @code{Aux_DEC} or
1344 you can construct your own extension unit following the above
1345 definition. Note that such a package is a child of @code{System}
1346 and thus is considered part of the implementation. To compile
1347 it you will have to use the appropriate switch for compiling
1348 system units. See the GNAT User's Guide for details.
1351 @item pragma External
1357 [ Convention =>] convention_IDENTIFIER,
1358 [ Entity =>] local_NAME
1359 [, [External_Name =>] static_string_EXPRESSION ]
1360 [, [Link_Name =>] static_string_EXPRESSION ]);
1364 This pragma is identical in syntax and semantics to pragma
1365 @code{Export} as defined in the Ada Reference Manual. It is
1366 provided for compatibility with some Ada 83 compilers that
1367 used this pragma for exactly the same purposes as pragma
1368 @code{Export} before the latter was standardized.
1370 @cindex Dec Ada 83 casing compatibility
1371 @cindex External Names, casing
1372 @cindex Casing of External names
1373 @findex External_Name_Casing
1374 @item pragma External_Name_Casing
1379 pragma External_Name_Casing (
1380 Uppercase | Lowercase
1381 [, Uppercase | Lowercase | As_Is]);
1385 This pragma provides control over the casing of external names associated
1386 with Import and Export pragmas. There are two cases to consider:
1389 @item Implicit external names
1390 Implicit external names are derived from identifiers. The most common case
1391 arises when a standard Ada 95 Import or Export pragma is used with only two
1395 pragma Import (C, C_Routine);
1399 Since Ada is a case insensitive language, the spelling of the identifier in
1400 the Ada source program does not provide any information on the desired
1401 casing of the external name, and so a convention is needed. In GNAT the
1402 default treatment is that such names are converted to all lower case
1403 letters. This corresponds to the normal C style in many environments.
1404 The first argument of pragma @code{External_Name_Casing} can be used to
1405 control this treatment. If @code{Uppercase} is specified, then the name
1406 will be forced to all uppercase letters. If @code{Lowercase} is specified,
1407 then the normal default of all lower case letters will be used.
1409 This same implicit treatment is also used in the case of extended DEC Ada 83
1410 compatible Import and Export pragmas where an external name is explicitly
1411 specified using an identifier rather than a string.
1413 @item Explicit external names
1414 Explicit external names are given as string literals. The most common case
1415 arises when a standard Ada 95 Import or Export pragma is used with three
1419 pragma Import (C, C_Routine, "C_routine");
1423 In this case, the string literal normally provides the exact casing required
1424 for the external name. The second argument of pragma
1425 @code{External_Name_Casing} may be used to modify this behavior.
1426 If @code{Uppercase} is specified, then the name
1427 will be forced to all uppercase letters. If @code{Lowercase} is specified,
1428 then the name will be forced to all lowercase letters. A specification of
1429 @code{As_Is} provides the normal default behavior in which the casing is
1430 taken from the string provided.
1434 This pragma may appear anywhere that a pragma is valid. In particular, it
1435 can be used as a configuration pragma in the @file{gnat.adc} file, in which
1436 case it applies to all subsequent compilations, or it can be used as a program
1437 unit pragma, in which case it only applies to the current unit, or it can
1438 be used more locally to control individual Import/Export pragmas.
1440 It is primarily intended for use with OpenVMS systems, where many
1441 compilers convert all symbols to upper case by default. For interfacing to
1442 such compilers (e.g.@: the DEC C compiler), it may be convenient to use
1446 pragma External_Name_Casing (Uppercase, Uppercase);
1450 to enforce the upper casing of all external symbols.
1452 @findex Finalize_Storage_Only
1453 @item pragma Finalize_Storage_Only
1458 pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
1462 This pragma allows the compiler not to emit a Finalize call for objects
1463 defined at the library level. This is mostly useful for types where
1464 finalization is only used to deal with storage reclamation since in most
1465 environments it is not necessary to reclaim memory just before terminating
1466 execution, hence the name.
1469 @findex Float_Representation
1470 @item pragma Float_Representation
1475 pragma Float_Representation (FLOAT_REP);
1477 FLOAT_REP ::= VAX_Float | IEEE_Float
1481 This pragma is implemented only in the OpenVMS implementation of GNAT@.
1482 It allows control over the internal representation chosen for the predefined
1483 floating point types declared in the packages @code{Standard} and
1484 @code{System}. For further details on this pragma, see the
1485 DEC Ada Language Reference Manual, section 3.5.7a. Note that to use this
1486 pragma, the standard runtime libraries must be recompiled. See the
1487 description of the @code{GNAT LIBRARY} command in the OpenVMS version
1488 of the GNAT Users Guide for details on the use of this command.
1496 pragma Ident (static_string_EXPRESSION);
1500 This pragma provides a string identification in the generated object file,
1501 if the system supports the concept of this kind of identification string.
1502 The maximum permitted length of the string literal is 31 characters.
1503 This pragma is allowed only in the outermost declarative part or
1504 declarative items of a compilation unit.
1506 On OpenVMS systems, the effect of the pragma is identical to the effect of
1507 the DEC Ada 83 pragma of the same name.
1510 @findex Import_Exception
1511 @item pragma Import_Exception
1516 pragma Import_Exception (
1517 [Internal =>] LOCAL_NAME,
1518 [, [External =>] EXTERNAL_SYMBOL,]
1519 [, [Form =>] Ada | VMS]
1520 [, [Code =>] static_integer_EXPRESSION]);
1524 | static_string_EXPRESSION
1528 This pragma is implemented only in the OpenVMS implementation of GNAT@.
1529 It allows OpenVMS conditions (for example, from OpenVMS system services or
1530 other OpenVMS languages) to be propagated to Ada programs as Ada exceptions.
1531 The pragma specifies that the exception associated with an exception
1532 declaration in an Ada program be defined externally (in non-Ada code).
1533 For further details on this pragma, see the
1534 DEC Ada Language Reference Manual, section 13.9a.3.1.
1536 @findex Import_Function
1537 @item pragma Import_Function @dots{}
1542 pragma Import_Function (
1543 [Internal =>] LOCAL_NAME,
1544 [, [External =>] EXTERNAL_SYMBOL]
1545 [, [Parameter_Types =>] PARAMETER_TYPES]
1546 [, [Result_Type =>] SUBTYPE_MARK]
1547 [, [Mechanism =>] MECHANISM]
1548 [, [Result_Mechanism =>] MECHANISM_NAME]
1549 [, [First_Optional_Parameter =>] IDENTIFIER]);
1553 | static_string_EXPRESSION
1557 | SUBTYPE_MARK @{, SUBTYPE_MARK@}
1561 | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
1563 MECHANISM_ASSOCIATION ::=
1564 [formal_parameter_NAME =>] MECHANISM_NAME
1569 | Descriptor [([Class =>] CLASS_NAME)]
1571 CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
1574 This pragma is used in conjunction with a pragma @code{Import} to
1575 specify additional information for an imported function. The pragma
1576 @code{Import} (or equivalent pragma @code{Interface}) must precede the
1577 @code{Import_Function} pragma and both must appear in the same
1578 declarative part as the function specification.
1580 The @var{Internal_Name} argument must uniquely designate
1581 the function to which the
1582 pragma applies. If more than one function name exists of this name in
1583 the declarative part you must use the @code{Parameter_Types} and
1584 @var{Result_Type} parameters to achieve the required unique
1585 designation. Subtype marks in these parameters must exactly match the
1586 subtypes in the corresponding function specification, using positional
1587 notation to match parameters with subtype marks.
1589 You may optionally use the @var{Mechanism} and @var{Result_Mechanism}
1590 parameters to specify passing mechanisms for the
1591 parameters and result. If you specify a single mechanism name, it
1592 applies to all parameters. Otherwise you may specify a mechanism on a
1593 parameter by parameter basis using either positional or named
1594 notation. If the mechanism is not specified, the default mechanism
1598 @cindex Passing by descriptor
1599 Passing by descriptor is supported only on the to OpenVMS ports of GNAT@.
1601 @code{First_Optional_Parameter} applies only to OpenVMS ports of GNAT@.
1602 It specifies that the designated parameter and all following parameters
1603 are optional, meaning that they are not passed at the generated code
1604 level (this is distinct from the notion of optional parameters in Ada
1605 where the parameters are passed anyway with the designated optional
1606 parameters). All optional parameters must be of mode @code{IN} and have
1607 default parameter values that are either known at compile time
1608 expressions, or uses of the @code{'Null_Parameter} attribute.
1610 @findex Import_Object
1611 @item pragma Import_Object
1616 pragma Import_Object
1617 [Internal =>] LOCAL_NAME,
1618 [, [External =>] EXTERNAL_SYMBOL],
1619 [, [Size =>] EXTERNAL_SYMBOL])
1623 | static_string_EXPRESSION
1627 This pragma designates an object as imported, and apart from the
1628 extended rules for external symbols, is identical in effect to the use of
1629 the normal @code{Import} pragma applied to an object. Unlike the
1630 subprogram case, you need not use a separate @code{Import} pragma,
1631 although you may do so (and probably should do so from a portability
1632 point of view). @var{size} is syntax checked, but otherwise ignored by
1635 @findex Import_Procedure
1636 @item pragma Import_Procedure
1641 pragma Import_Procedure (
1642 [Internal =>] LOCAL_NAME,
1643 [, [External =>] EXTERNAL_SYMBOL]
1644 [, [Parameter_Types =>] PARAMETER_TYPES]
1645 [, [Mechanism =>] MECHANISM]
1646 [, [First_Optional_Parameter =>] IDENTIFIER]);
1650 | static_string_EXPRESSION
1654 | SUBTYPE_MARK @{, SUBTYPE_MARK@}
1658 | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
1660 MECHANISM_ASSOCIATION ::=
1661 [formal_parameter_NAME =>] MECHANISM_NAME
1666 | Descriptor [([Class =>] CLASS_NAME)]
1668 CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
1672 This pragma is identical to @code{Import_Function} except that it
1673 applies to a procedure rather than a function and the parameters
1674 @code{Result_Type} and @code{Result_Mechanism} are not permitted.
1676 @findex Import_Valued_Procedure
1677 @item pragma Import_Valued_Procedure @dots{}
1682 pragma Import_Valued_Procedure (
1683 [Internal =>] LOCAL_NAME,
1684 [, [External =>] EXTERNAL_SYMBOL]
1685 [, [Parameter_Types =>] PARAMETER_TYPES]
1686 [, [Mechanism =>] MECHANISM]
1687 [, [First_Optional_Parameter =>] IDENTIFIER]);
1691 | static_string_EXPRESSION
1695 | SUBTYPE_MARK @{, SUBTYPE_MARK@}
1699 | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
1701 MECHANISM_ASSOCIATION ::=
1702 [formal_parameter_NAME =>] MECHANISM_NAME
1707 | Descriptor [([Class =>] CLASS_NAME)]
1709 CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
1713 This pragma is identical to @code{Import_Procedure} except that the
1714 first parameter of @var{local_name}, which must be present, must be of
1715 mode @code{OUT}, and externally the subprogram is treated as a function
1716 with this parameter as the result of the function. The purpose of this
1717 capability is to allow the use of @code{OUT} and @code{IN OUT}
1718 parameters in interfacing to external functions (which are not permitted
1719 in Ada functions). You may optionally use the @code{Mechanism}
1720 parameters to specify passing mechanisms for the parameters.
1721 If you specify a single mechanism name, it applies to all parameters.
1722 Otherwise you may specify a mechanism on a parameter by parameter
1723 basis using either positional or named notation. If the mechanism is not
1724 specified, the default mechanism is used.
1726 Note that it is important to use this pragma in conjunction with a separate
1727 pragma Import that specifies the desired convention, since otherwise the
1728 default convention is Ada, which is almost certainly not what is required.
1730 @findex Initialize_Scalars
1731 @cindex debugging with Initialize_Scalars
1732 @item pragma Initialize_Scalars
1737 pragma Initialize_Scalars;
1741 This pragma is similar to @code{Normalize_Scalars} conceptually but has
1742 two important differences. First, there is no requirement for the pragma
1743 to be used uniformly in all units of a partition, in particular, it is fine
1744 to use this just for some or all of the application units of a partition,
1745 without needing to recompile the run-time library.
1747 In the case where some units are compiled with the pragma, and some without,
1748 then a declaration of a variable where the type is defined in package
1749 Standard or is locally declared will always be subject to initialization,
1750 as will any declaration of a scalar variable. For composite variables,
1751 whether the variable is initialized may also depend on whether the package
1752 in which the type of the variable is declared is compiled with the pragma.
1754 The other important difference is that there is control over the value used
1755 for initializing scalar objects. At bind time, you can select whether to
1756 initialize with invalid values (like Normalize_Scalars), or with high or
1757 low values, or with a specified bit pattern. See the users guide for binder
1758 options for specifying these cases.
1760 This means that you can compile a program, and then without having to
1761 recompile the program, you can run it with different values being used
1762 for initializing otherwise uninitialized values, to test if your program
1763 behavior depends on the choice. Of course the behavior should not change,
1764 and if it does, then most likely you have an erroneous reference to an
1765 uninitialized value.
1767 Note that pragma @code{Initialize_Scalars} is particularly useful in
1768 conjunction with the enhanced validity checking that is now provided
1769 in GNAT, which checks for invalid values under more conditions.
1770 Using this feature (see description of the @code{-gnatv} flag in the
1771 users guide) in conjunction with pragma @code{Initialize_Scalars}
1772 provides a powerful new tool to assist in the detection of problems
1773 caused by uninitialized variables.
1775 @findex Inline_Always
1776 @item pragma Inline_Always
1781 pragma Inline_Always (NAME [, NAME]);
1785 Similar to pragma @code{Inline} except that inlining is not subject to
1786 the use of option @code{-gnatn} for inter-unit inlining.
1788 @findex Inline_Generic
1789 @item pragma Inline_Generic
1794 pragma Inline_Generic (generic_package_NAME)
1798 This is implemented for compatibility with DEC Ada 83 and is recognized,
1799 but otherwise ignored, by GNAT@. All generic instantiations are inlined
1800 by default when using GNAT@.
1803 @item pragma Interface
1809 [Convention =>] convention_identifier,
1810 [Entity =>] local_name
1811 [, [External_Name =>] static_string_expression],
1812 [, [Link_Name =>] static_string_expression]);
1816 This pragma is identical in syntax and semantics to
1817 the standard Ada 95 pragma @code{Import}. It is provided for compatibility
1818 with Ada 83. The definition is upwards compatible both with pragma
1819 @code{Interface} as defined in the Ada 83 Reference Manual, and also
1820 with some extended implementations of this pragma in certain Ada 83
1823 @findex Interface_Name
1824 @item pragma Interface_Name
1829 pragma Interface_Name (
1830 [Entity =>] LOCAL_NAME
1831 [, [External_Name =>] static_string_EXPRESSION]
1832 [, [Link_Name =>] static_string_EXPRESSION]);
1836 This pragma provides an alternative way of specifying the interface name
1837 for an interfaced subprogram, and is provided for compatibility with Ada
1838 83 compilers that use the pragma for this purpose. You must provide at
1839 least one of @var{External_Name} or @var{Link_Name}.
1842 @item pragma License
1843 @cindex License checking
1848 pragma License (Unrestricted | GPL | Modified_GPL | Restricted);
1852 This pragma is provided to allow automated checking for appropriate license
1853 conditions with respect to the standard and modified GPL@. A pragma @code{License},
1854 which is a configuration pragma that typically appears at the start of a
1855 source file or in a separate @file{gnat.adc} file, specifies the licensing
1856 conditions of a unit as follows:
1860 This is used for a unit that can be freely used with no license restrictions.
1861 Examples of such units are public domain units, and units from the Ada
1865 This is used for a unit that is licensed under the unmodified GPL, and which
1866 therefore cannot be @code{with}'ed by a restricted unit.
1869 This is used for a unit licensed under the GNAT modified GPL that includes
1870 a special exception paragraph that specifically permits the inclusion of
1871 the unit in programs without requiring the entire program to be released
1872 under the GPL@. This is the license used for the GNAT run-time which ensures
1873 that the run-time can be used freely in any program without GPL concerns.
1876 This is used for a unit that is restricted in that it is not permitted to
1877 depend on units that are licensed under the GPL@. Typical examples are
1878 proprietary code that is to be released under more restrictive license
1879 conditions. Note that restricted units are permitted to @code{with} units
1880 which are licensed under the modified GPL (this is the whole point of the
1886 Normally a unit with no @code{License} pragma is considered to have an
1887 unknown license, and no checking is done. However, standard GNAT headers
1888 are recognized, and license information is derived from them as follows.
1892 A GNAT license header starts with a line containing 78 hyphens. The following
1893 comment text is searched for the appearence of any of the following strings.
1895 If the string ``GNU General Public License'' is found, then the unit is assumed
1896 to have GPL license, unless the string ``As a special exception'' follows, in
1897 which case the license is assumed to be modified GPL@.
1899 If one of the strings
1900 ``This specification is adapated from the Ada Semantic Interface'' or
1901 ``This specification is derived from the Ada Reference Manual'' is found
1902 then the unit is assumed to be unrestricted.
1906 These default actions means that a program with a restricted license pragma
1907 will automatically get warnings if a GPL unit is inappropriately
1908 @code{with}'ed. For example, the program:
1913 procedure Secret_Stuff is
1919 if compiled with pragma @code{License} (@code{Restricted}) in a
1920 @file{gnat.adc} file will generate the warning:
1925 >>> license of withed unit "Sem_Ch3" is incompatible
1927 2. with GNAT.Sockets;
1928 3. procedure Secret_Stuff is
1931 Here we get a warning on @code{Sem_Ch3} since it is part of the GNAT
1932 compiler and is licensed under the
1933 GPL, but no warning for @code{GNAT.Sockets} which is part of the GNAT
1934 run time, and is therefore licensed under the modified GPL@.
1937 @item pragma Link_With
1942 pragma Link_With (static_string_EXPRESSION @{,static_string_EXPRESSION@});
1946 This pragma is provided for compatibility with certain Ada 83 compilers.
1947 It has exactly the same effect as pragma @code{Linker_Options} except
1948 that spaces occurring within one of the string expressions are treated
1949 as separators. For example, in the following case:
1952 pragma Link_With ("-labc -ldef");
1956 results in passing the strings @code{-labc} and @code{-ldef} as two
1957 separate arguments to the linker. In addition pragma Link_With allows
1958 multiple arguments, with the same effect as successive pragmas.
1960 @findex Linker_Alias
1961 @item pragma Linker_Alias
1966 pragma Linker_Alias (
1967 [Entity =>] LOCAL_NAME
1968 [Alias =>] static_string_EXPRESSION);
1972 This pragma establishes a linker alias for the given named entity. For
1973 further details on the exact effect, consult the GCC manual.
1975 @findex Linker_Section
1976 @item pragma Linker_Section
1981 pragma Linker_Section (
1982 [Entity =>] LOCAL_NAME
1983 [Section =>] static_string_EXPRESSION);
1987 This pragma specifies the name of the linker section for the given entity.
1988 For further details on the exact effect, consult the GCC manual.
1991 @item pragma No_Run_Time
2000 This is a configuration pragma that makes sure the user code does not
2001 use nor need anything from the GNAT run time. This is mostly useful in
2002 context where code certification is required. Please consult the
2003 @cite{GNAT Pro High-Integrity Edition User's Guide} for additional information.
2005 @findex Normalize_Scalars
2006 @item pragma Normalize_Scalars
2011 pragma Normalize_Scalars;
2015 This is a language defined pragma which is fully implemented in GNAT@. The
2016 effect is to cause all scalar objects that are not otherwise initialized
2017 to be initialized. The initial values are implementation dependent and
2021 @item Standard.Character
2023 Objects whose root type is Standard.Character are initialized to
2024 Character'Last. This will be out of range of the subtype only if
2025 the subtype range excludes this value.
2027 @item Standard.Wide_Character
2029 Objects whose root type is Standard.Wide_Character are initialized to
2030 Wide_Character'Last. This will be out of range of the subtype only if
2031 the subtype range excludes this value.
2035 Objects of an integer type are initialized to base_type'First, where
2036 base_type is the base type of the object type. This will be out of range
2037 of the subtype only if the subtype range excludes this value. For example,
2038 if you declare the subtype:
2041 subtype Ityp is integer range 1 .. 10;
2045 then objects of type x will be initialized to Integer'First, a negative
2046 number that is certainly outside the range of subtype @code{Ityp}.
2049 Objects of all real types (fixed and floating) are initialized to
2050 base_type'First, where base_Type is the base type of the object type.
2051 This will be out of range of the subtype only if the subtype range
2052 excludes this value.
2055 Objects of a modular type are initialized to typ'Last. This will be out
2056 of range of the subtype only if the subtype excludes this value.
2058 @item Enumeration types
2059 Objects of an enumeration type are initialized to all one-bits, i.e.@: to
2060 the value @code{2 ** typ'Size - 1}. This will be out of range of the enumeration
2061 subtype in all cases except where the subtype contains exactly
2062 2**8, 2**16, or 2**32 elements.
2068 @item pragma Long_Float
2073 pragma Long_Float (FLOAT_FORMAT);
2075 FLOAT_FORMAT ::= D_Float | G_Float
2079 This pragma is implemented only in the OpenVMS implementation of GNAT@.
2080 It allows control over the internal representation chosen for the predefined
2081 type @code{Long_Float} and for floating point type representations with
2082 @code{digits} specified in the range 7 through 15.
2083 For further details on this pragma, see the
2084 @cite{DEC Ada Language Reference Manual}, section 3.5.7b. Note that to use this
2085 pragma, the standard runtime libraries must be recompiled. See the
2086 description of the @code{GNAT LIBRARY} command in the OpenVMS version
2087 of the GNAT User's Guide for details on the use of this command.
2089 @findex Machine_Attribute
2090 @item pragma Machine_Attribute @dots{}
2095 pragma Machine_Attribute (
2096 [Attribute_Name =>] string_EXPRESSION,
2097 [Entity =>] LOCAL_NAME);
2100 Machine dependent attributes can be specified for types and/or
2101 declarations. Currently only subprogram entities are supported. This
2102 pragma is semantically equivalent to
2103 @code{__attribute__((@var{string_expression}))} in GNU C,
2104 where @code{@var{string_expression}} is
2105 recognized by the GNU C macros @code{VALID_MACHINE_TYPE_ATTRIBUTE} and
2106 @code{VALID_MACHINE_DECL_ATTRIBUTE} which are defined in the
2107 configuration header file @file{tm.h} for each machine. See the GCC
2108 manual for further information.
2111 @findex Main_Storage
2112 @item pragma Main_Storage
2118 (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
2120 MAIN_STORAGE_OPTION ::=
2121 [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
2122 | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
2127 This pragma is provided for compatibility with OpenVMS Vax Systems. It has
2128 no effect in GNAT, other than being syntax checked. Note that the pragma
2129 also has no effect in DEC Ada 83 for OpenVMS Alpha Systems.
2132 @item pragma No_Return
2137 pragma No_Return (procedure_LOCAL_NAME);
2141 @var{procedure_local_NAME} must refer to one or more procedure
2142 declarations in the current declarative part. A procedure to which this
2143 pragma is applied may not contain any explicit @code{return} statements,
2144 and also may not contain any implicit return statements from falling off
2145 the end of a statement sequence. One use of this pragma is to identify
2146 procedures whose only purpose is to raise an exception.
2148 Another use of this pragma is to suppress incorrect warnings about
2149 missing returns in functions, where the last statement of a function
2150 statement sequence is a call to such a procedure.
2153 @item pragma Passive
2158 pragma Passive ([Semaphore | No]);
2162 Syntax checked, but otherwise ignored by GNAT@. This is recognized for
2163 compatibility with DEC Ada 83 implementations, where it is used within a
2164 task definition to request that a task be made passive. If the argument
2165 @code{Semaphore} is present, or no argument is omitted, then DEC Ada 83
2166 treats the pragma as an assertion that the containing task is passive
2167 and that optimization of context switch with this task is permitted and
2168 desired. If the argument @code{No} is present, the task must not be
2169 optimized. GNAT does not attempt to optimize any tasks in this manner
2170 (since protected objects are available in place of passive tasks).
2173 @item pragma Polling
2178 pragma Polling (ON | OFF);
2182 This pragma controls the generation of polling code. This is normally off.
2183 If @code{pragma Polling (ON)} is used then periodic calls are generated to
2184 the routine @code{Ada.Exceptions.Poll}. This routine is a separate unit in the
2185 runtime library, and can be found in file @file{a-excpol.adb}.
2187 Pragma @code{Polling} can appear as a configuration pragma (for example it can be
2188 placed in the @file{gnat.adc} file) to enable polling globally, or it can be used
2189 in the statement or declaration sequence to control polling more locally.
2191 A call to the polling routine is generated at the start of every loop and
2192 at the start of every subprogram call. This guarantees that the @code{Poll}
2193 routine is called frequently, and places an upper bound (determined by
2194 the complexity of the code) on the period between two @code{Poll} calls.
2196 The primary purpose of the polling interface is to enable asynchronous
2197 aborts on targets that cannot otherwise support it (for example Windows
2198 NT), but it may be used for any other purpose requiring periodic polling.
2199 The standard version is null, and can be replaced by a user program. This
2200 will require re-compilation of the @code{Ada.Exceptions} package that can be found
2201 in files @file{a-except.ads} and @file{a-except.adb}.
2203 A standard alternative unit (in file @file{4wexcpol.adb} in the standard GNAT
2204 distribution) is used to enable the asynchronous abort capability on
2205 targets that do not normally support the capability. The version of @code{Poll}
2206 in this file makes a call to the appropriate runtime routine to test for
2209 Note that polling can also be enabled by use of the @code{-gnatP} switch. See
2210 the @cite{GNAT User's Guide} for details.
2212 @findex Propagate_Exceptions
2213 @cindex Zero Cost Exceptions
2214 @item pragma Propagate_Exceptions
2219 pragma Propagate_Exceptions (subprogram_LOCAL_NAME);
2223 This pragma indicates that the given entity, which is the name of an
2224 imported foreign-language subprogram may receive an Ada exception,
2225 and that the exception should be propagated. It is relevant only if
2226 zero cost exception handling is in use, and is thus never needed if
2227 the alternative @code{longjmp} / @code{setjmp} implementation of exceptions is used
2228 (although it is harmless to use it in such cases).
2230 The implementation of fast exceptions always properly propagates
2231 exceptions through Ada code, as described in the Ada Reference Manual.
2232 However, this manual is silent about the propagation of exceptions
2233 through foreign code. For example, consider the
2234 situation where @code{P1} calls
2235 @code{P2}, and @code{P2} calls @code{P3}, where
2236 @code{P1} and @code{P3} are in Ada, but @code{P2} is in C@.
2237 @code{P3} raises an Ada exception. The question is whether or not
2238 it will be propagated through @code{P2} and can be handled in
2241 For the @code{longjmp} / @code{setjmp} implementation of exceptions, the answer is
2242 always yes. For some targets on which zero cost exception handling
2243 is implemented, the answer is also always yes. However, there are
2244 some targets, notably in the current version all x86 architecture
2245 targets, in which the answer is that such propagation does not
2246 happen automatically. If such propagation is required on these
2247 targets, it is mandatory to use @code{Propagate_Exceptions} to
2248 name all foreign language routines through which Ada exceptions
2251 @findex Psect_Object
2252 @item pragma Psect_Object
2258 [Internal =>] LOCAL_NAME,
2259 [, [External =>] EXTERNAL_SYMBOL]
2260 [, [Size =>] EXTERNAL_SYMBOL]
2264 | static_string_EXPRESSION
2268 This pragma is identical in effect to pragma @code{Common_Object}.
2270 @findex Pure_Function
2271 @item pragma Pure_Function
2276 pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
2279 This pragma appears in the same declarative part as a function
2280 declaration (or a set of function declarations if more than one
2281 overloaded declaration exists, in which case the pragma applies
2282 to all entities). If specifies that the function @code{Entity} is
2283 to be considered pure for the purposes of code generation. This means
2284 that the compiler can assume that there are no side effects, and
2285 in particular that two calls with identical arguments produce the
2286 same result. It also means that the function can be used in an
2289 Note that, quite deliberately, there are no static checks to try
2290 to ensure that this promise is met, so @code{Pure_Function} can be used
2291 with functions that are conceptually pure, even if they do modify
2292 global variables. For example, a square root function that is
2293 instrumented to count the number of times it is called is still
2294 conceptually pure, and can still be optimized, even though it
2295 modifies a global variable (the count). Memo functions are another
2296 example (where a table of previous calls is kept and consulted to
2297 avoid re-computation).
2300 Note: Most functions in a @code{Pure} package are automatically pure, and
2301 there is no need to use pragma @code{Pure_Function} for such functions. An
2302 exception is any function that has at least one formal of type
2303 @code{System.Address} or a type derived from it. Such functions are not
2304 considered pure by default, since the compiler assumes that the
2305 @code{Address} parameter may be functioning as a pointer and that the
2306 referenced data may change even if the address value does not. The use
2307 of pragma @code{Pure_Function} for such a function will override this default
2308 assumption, and cause the compiler to treat such a function as pure.
2310 Note: If pragma @code{Pure_Function} is applied to a renamed function, it
2311 applies to the underlying renamed function. This can be used to
2312 disambiguate cases of overloading where some but not all functions
2313 in a set of overloaded functions are to be designated as pure.
2316 @item pragma Ravenscar
2325 A configuration pragma that establishes the following set of restrictions:
2328 @item No_Abort_Statements
2329 [RM D.7] There are no abort_statements, and there are
2330 no calls to Task_Identification.Abort_Task.
2332 @item No_Select_Statements
2333 There are no select_statements.
2335 @item No_Task_Hierarchy
2336 [RM D.7] All (non-environment) tasks depend
2337 directly on the environment task of the partition.
2339 @item No_Task_Allocators
2340 [RM D.7] There are no allocators for task types
2341 or types containing task subcomponents.
2343 @item No_Dynamic_Priorities
2344 [RM D.7] There are no semantic dependencies on the package Dynamic_Priorities.
2346 @item No_Terminate_Alternatives
2347 [RM D.7] There are no selective_accepts with terminate_alternatives
2349 @item No_Dynamic_Interrupts
2350 There are no semantic dependencies on Ada.Interrupts.
2352 @item No_Protected_Type_Allocators
2353 There are no allocators for protected types or
2354 types containing protected subcomponents.
2356 @item No_Local_Protected_Objects
2357 Protected objects and access types that designate
2358 such objects shall be declared only at library level.
2361 Requeue statements are not allowed.
2364 There are no semantic dependencies on the package Ada.Calendar.
2366 @item No_Relative_Delay
2367 There are no delay_relative_statements.
2369 @item No_Task_Attributes
2370 There are no semantic dependencies on the Ada.Task_Attributes package and
2371 there are no references to the attributes Callable and Terminated [RM 9.9].
2373 @item Static_Storage_Size
2374 The expression for pragma Storage_Size is static.
2376 @item Boolean_Entry_Barriers
2377 Entry barrier condition expressions shall be boolean
2378 objects which are declared in the protected type
2379 which contains the entry.
2381 @item Max_Asynchronous_Select_Nesting = 0
2382 [RM D.7] Specifies the maximum dynamic nesting level of asynchronous_selects.
2383 A value of zero prevents the use of any asynchronous_select.
2385 @item Max_Task_Entries = 0
2386 [RM D.7] Specifies the maximum number of entries
2387 per task. The bounds of every entry family
2388 of a task unit shall be static, or shall be
2389 defined by a discriminant of a subtype whose
2390 corresponding bound is static. A value of zero
2391 indicates that no rendezvous are possible. For
2392 the Ravenscar pragma, the value of Max_Task_Entries is always
2395 @item Max_Protected_Entries = 1
2396 [RM D.7] Specifies the maximum number of entries per
2397 protected type. The bounds of every entry family of
2398 a protected unit shall be static, or shall be defined
2399 by a discriminant of a subtype whose corresponding
2400 bound is static. For the Ravenscar pragma the value of
2401 Max_Protected_Entries is always 1.
2403 @item Max_Select_Alternatives = 0
2404 [RM D.7] Specifies the maximum number of alternatives in a selective_accept.
2405 For the Ravenscar pragma the value if always 0.
2407 @item No_Task_Termination
2408 Tasks which terminate are erroneous.
2410 @item No_Entry_Queue
2411 No task can be queued on a protected entry. Note that this restrictions is
2412 checked at run time. The violation of this restriction generates a
2413 Program_Error exception.
2417 This set of restrictions corresponds to the definition of the ``Ravenscar
2418 Profile'' for limited tasking, devised and published by the @cite{International
2419 Real-Time Ada Workshop}, 1997.
2421 The above set is a superset of the restrictions provided by pragma
2422 @code{Restricted_Run_Time}, it includes six additional restrictions
2423 (@code{Boolean_Entry_Barriers}, @code{No_Select_Statements},
2424 @code{No_Calendar}, @code{Static_Storage_Size},
2425 @code{No_Relative_Delay} and @code{No_Task_Termination}). This means
2426 that pragma @code{Ravenscar}, like the pragma @code{Restricted_Run_Time}, automatically
2427 causes the use of a simplified, more efficient version of the tasking
2430 @findex Restricted_Run_Time
2431 @item pragma Restricted_Run_Time
2436 pragma Restricted_Run_Time
2440 A configuration pragma that establishes the following set of restrictions:
2443 @item No_Abort_Statements
2444 @item No_Asynchronous_Control
2445 @item No_Entry_Queue
2446 @item No_Task_Hierarchy
2447 @item No_Task_Allocators
2448 @item No_Dynamic_Priorities
2449 @item No_Terminate_Alternatives
2450 @item No_Dynamic_Interrupts
2451 @item No_Protected_Type_Allocators
2452 @item No_Local_Protected_Objects
2454 @item No_Task_Attributes
2455 @item Max_Asynchronous_Select_Nesting = 0
2456 @item Max_Task_Entries = 0
2457 @item Max_Protected_Entries = 1
2458 @item Max_Select_Alternatives = 0
2462 This set of restrictions causes the automatic selection of a simplified
2463 version of the run time that provides improved performance for the
2464 limited set of tasking functionality permitted by this set of restrictions.
2466 @findex Share_Generic
2467 @item pragma Share_Generic
2472 pragma Share_Generic (NAME @{, NAME@});
2476 This pragma is recognized for compatibility with other Ada compilers
2477 but is ignored by GNAT@. GNAT does not provide the capability for
2478 sharing of generic code. All generic instantiations result in making
2479 an inlined copy of the template with appropriate substitutions.
2481 @findex Source_File_Name
2482 @item pragma Source_File_Name
2487 pragma Source_File_Name (
2488 [Unit_Name =>] unit_NAME,
2489 Spec_File_Name => STRING_LITERAL);
2491 pragma Source_File_Name (
2492 [Unit_Name =>] unit_NAME,
2493 Body_File_Name => STRING_LITERAL);
2497 Use this to override the normal naming convention. It is a configuration
2498 pragma, and so has the usual applicability of configuration pragmas
2499 (i.e.@: it applies to either an entire partition, or to all units in a
2500 compilation, or to a single unit, depending on how it is used.
2501 @var{unit_name} is mapped to @var{file_name_literal}. The identifier for
2502 the second argument is required, and indicates whether this is the file
2503 name for the spec or for the body.
2505 Another form of the @code{Source_File_Name} pragma allows
2506 the specification of patterns defining alternative file naming schemes
2507 to apply to all files.
2510 pragma Source_File_Name
2511 (Spec_File_Name => STRING_LITERAL
2512 [,Casing => CASING_SPEC]
2513 [,Dot_Replacement => STRING_LITERAL]);
2515 pragma Source_File_Name
2516 (Body_File_Name => STRING_LITERAL
2517 [,Casing => CASING_SPEC]
2518 [,Dot_Replacement => STRING_LITERAL]);
2520 pragma Source_File_Name
2521 (Subunit_File_Name => STRING_LITERAL
2522 [,Casing => CASING_SPEC]
2523 [,Dot_Replacement => STRING_LITERAL]);
2525 CASING_SPEC ::= Lowercase | Uppercase | Mixedcase
2529 The first argument is a pattern that contains a single asterisk indicating
2530 the point at which the unit name is to be inserted in the pattern string
2531 to form the file name. The second argument is optional. If present it
2532 specifies the casing of the unit name in the resulting file name string.
2533 The default is lower case. Finally the third argument allows for systematic
2534 replacement of any dots in the unit name by the specified string literal.
2536 For more details on the use of the @code{Source_File_Name} pragma,
2537 see the sections ``Using Other File Names'' and
2538 ``Alternative File Naming Schemes'' in the @cite{GNAT User's Guide}.
2540 @findex Source_Reference
2541 @item pragma Source_Reference
2546 pragma Source_Reference (INTEGER_LITERAL,
2551 This pragma must appear as the first line of a source file.
2552 @var{integer_literal} is the logical line number of the line following
2553 the pragma line (for use in error messages and debugging
2554 information). @var{string_literal} is a static string constant that
2555 specifies the file name to be used in error messages and debugging
2556 information. This is most notably used for the output of @code{gnatchop}
2557 with the @code{-r} switch, to make sure that the original unchopped
2558 source file is the one referred to.
2560 The second argument must be a string literal, it cannot be a static
2561 string expression other than a string literal. This is because its value
2562 is needed for error messages issued by all phases of the compiler.
2564 @findex Stream_Convert
2565 @item pragma Stream_Convert
2570 pragma Stream_Convert (
2571 [Entity =>] type_LOCAL_NAME,
2572 [Read =>] function_NAME,
2573 [Write =>] function NAME);
2577 This pragma provides an efficient way of providing stream functions for
2578 types defined in packages. Not only is it simpler to use than declaring
2579 the necessary functions with attribute representation clauses, but more
2580 significantly, it allows the declaration to made in such a way that the
2581 stream packages are not loaded unless they are needed. The use of
2582 the Stream_Convert pragma adds no overhead at all, unless the stream
2583 attributes are actually used on the designated type.
2585 The first argument specifies the type for which stream functions are
2586 provided. The second parameter provides a function used to read values
2587 of this type. It must name a function whose argument type may be any
2588 subtype, and whose returned type must be the type given as the first
2589 argument to the pragma.
2591 The meaning of the @var{Read}
2592 parameter is that if a stream attribute directly
2593 or indirectly specifies reading of the type given as the first parameter,
2594 then a value of the type given as the argument to the Read function is
2595 read from the stream, and then the Read function is used to convert this
2596 to the required target type.
2598 Similarly the @var{Write} parameter specifies how to treat write attributes
2599 that directly or indirectly apply to the type given as the first parameter.
2600 It must have an input parameter of the type specified by the first parameter,
2601 and the return type must be the same as the input type of the Read function.
2602 The effect is to first call the Write function to convert to the given stream
2603 type, and then write the result type to the stream.
2605 The Read and Write functions must not be overloaded subprograms. If necessary
2606 renamings can be supplied to meet this requirement.
2607 The usage of this attribute is best illustrated by a simple example, taken
2608 from the GNAT implementation of package Ada.Strings.Unbounded:
2611 function To_Unbounded (S : String)
2612 return Unbounded_String
2613 renames To_Unbounded_String;
2615 pragma Stream_Convert
2616 (Unbounded_String, To_Unbounded, To_String);
2620 The specifications of the referenced functions, as given in the Ada 95
2621 Reference Manual are:
2624 function To_Unbounded_String (Source : String)
2625 return Unbounded_String;
2627 function To_String (Source : Unbounded_String)
2632 The effect is that if the value of an unbounded string is written to a
2633 stream, then the representation of the item in the stream is in the same
2634 format used for @code{Standard.String}, and this same representation is
2635 expected when a value of this type is read from the stream.
2637 @findex Style_Checks
2638 @item pragma Style_Checks
2643 pragma Style_Checks (string_LITERAL | ALL_CHECKS |
2644 On | Off [, LOCAL_NAME]);
2648 This pragma is used in conjunction with compiler switches to control the
2649 built in style checking provided by GNAT@. The compiler switches, if set
2650 provide an initial setting for the switches, and this pragma may be used
2651 to modify these settings, or the settings may be provided entirely by
2652 the use of the pragma. This pragma can be used anywhere that a pragma
2653 is legal, including use as a configuration pragma (including use in
2654 the @file{gnat.adc} file).
2656 The form with a string literal specifies which style options are to be
2657 activated. These are additive, so they apply in addition to any previously
2658 set style check options. The codes for the options are the same as those
2659 used in the @code{-gnaty} switch to @code{gcc} or @code{gnatmake}.
2660 For example the following two methods can be used to enable
2664 pragma Style_Checks ("l");
2665 gcc -c -gnatyl @dots{}
2669 The form ALL_CHECKS activates all standard checks (its use is equivalent
2670 to the use of the @code{gnaty} switch with no options. See GNAT User's
2673 The forms with @code{Off} and @code{On}
2674 can be used to temporarily disable style checks
2675 as shown in the following example:
2681 pragma Style_Checks ("k"); -- requires keywords in lower case
2682 pragma Style_Checks (Off); -- turn off style checks
2683 NULL; -- this will not generate an error message
2684 pragma Style_Checks (On); -- turn style checks back on
2685 NULL; -- this will generate an error message
2689 Finally the two argument form is allowed only if the first argument is
2690 @code{On} or @code{Off}. The effect is to turn of semantic style checks
2691 for the specified entity, as shown in the following example:
2697 pragma Style_Checks ("r"); -- require consistency of identifier casing
2699 Rf1 : Integer := ARG; -- incorrect, wrong case
2700 pragma Style_Checks (Off, Arg);
2701 Rf2 : Integer := ARG; -- OK, no error
2705 @item pragma Subtitle
2710 pragma Subtitle ([Subtitle =>] STRING_LITERAL);
2714 This pragma is recognized for compatibility with other Ada compilers
2715 but is ignored by GNAT@.
2717 @findex Suppress_All
2718 @item pragma Suppress_All
2723 pragma Suppress_All;
2727 This pragma can only appear immediately following a compilation
2728 unit. The effect is to apply @code{Suppress (All_Checks)} to the unit
2729 which it follows. This pragma is implemented for compatibility with DEC
2730 Ada 83 usage. The use of pragma @code{Suppress (All_Checks)} as a normal
2731 configuration pragma is the preferred usage in GNAT@.
2733 @findex Suppress_Initialization
2734 @cindex Suppressing initialization
2735 @cindex Initialization, suppression of
2736 @item pragma Suppress_Initialization
2741 pragma Suppress_Initialization ([Entity =>] type_Name);
2745 This pragma suppresses any implicit or explicit initialization
2746 associated with the given type name for all variables of this type.
2749 @item pragma Task_Info
2754 pragma Task_Info (EXPRESSION);
2758 This pragma appears within a task definition (like pragma
2759 @code{Priority}) and applies to the task in which it appears. The
2760 argument must be of type @code{System.Task_Info.Task_Info_Type}.
2761 The @code{Task_Info} pragma provides system dependent control over
2762 aspect of tasking implementation, for example, the ability to map
2763 tasks to specific processors. For details on the facilities available
2764 for the version of GNAT that you are using, see the documentation
2765 in the specification of package System.Task_Info in the runtime
2769 @item pragma Task_Name
2774 pragma Task_Name (string_EXPRESSION);
2778 This pragma appears within a task definition (like pragma
2779 @code{Priority}) and applies to the task in which it appears. The
2780 argument must be of type String, and provides a name to be used for
2781 the task instance when the task is created. Note that this expression
2782 is not required to be static, and in particular, it can contain
2783 references to task discriminants. This facility can be used to
2784 provide different names for different tasks as they are created,
2785 as illustrated in the example below.
2787 The task name is recorded internally in the run-time structures
2788 and is accessible to tools like the debugger. In addition the
2789 routine @code{Ada.Task_Identification.Image} will return this
2790 string, with a unique task address appended.
2793 -- Example of the use of pragma Task_Name
2795 with Ada.Task_Identification;
2796 use Ada.Task_Identification;
2797 with Text_IO; use Text_IO;
2800 type Astring is access String;
2802 task type Task_Typ (Name : access String) is
2803 pragma Task_Name (Name.all);
2806 task body Task_Typ is
2807 Nam : constant String := Image (Current_Task);
2809 Put_Line ("-->" & Nam (1 .. 14) & "<--");
2812 type Ptr_Task is access Task_Typ;
2813 Task_Var : Ptr_Task;
2817 new Task_Typ (new String'("This is task 1"));
2819 new Task_Typ (new String'("This is task 2"));
2823 @findex Task_Storage
2824 @item pragma Task_Storage
2829 [Task_Type =>] LOCAL_NAME,
2830 [Top_Guard =>] static_integer_EXPRESSION);
2833 This pragma specifies the length of the guard area for tasks. The guard
2834 area is an additional storage area allocated to a task. A value of zero
2835 means that either no guard area is created or a minimal guard area is
2836 created, depending on the target. This pragma can appear anywhere a
2837 @code{Storage_Size} attribute definition clause is allowed for a task
2841 @item pragma Time_Slice
2846 pragma Time_Slice (static_duration_EXPRESSION);
2850 For implementations of GNAT on operating systems where it is possible
2851 to supply a time slice value, this pragma may be used for this purpose.
2852 It is ignored if it is used in a system that does not allow this control,
2853 or if it appears in other than the main program unit.
2855 Note that the effect of this pragma is identical to the effect of the
2856 DEC Ada 83 pragma of the same name when operating under OpenVMS systems.
2864 pragma Title (TITLING_OPTION [, TITLING OPTION]);
2867 [Title =>] STRING_LITERAL,
2868 | [Subtitle =>] STRING_LITERAL
2872 Syntax checked but otherwise ignored by GNAT@. This is a listing control
2873 pragma used in DEC Ada 83 implementations to provide a title and/or
2874 subtitle for the program listing. The program listing generated by GNAT
2875 does not have titles or subtitles.
2877 Unlike other pragmas, the full flexibility of named notation is allowed
2878 for this pragma, i.e.@: the parameters may be given in any order if named
2879 notation is used, and named and positional notation can be mixed
2880 following the normal rules for procedure calls in Ada.
2883 @findex Unchecked_Union
2884 @item pragma Unchecked_Union
2889 pragma Unchecked_Union (first_subtype_LOCAL_NAME)
2893 This pragma is used to declare that the specified type should be represented
2895 equivalent to a C union type, and is intended only for use in
2896 interfacing with C code that uses union types. In Ada terms, the named
2897 type must obey the following rules:
2901 It is a non-tagged non-limited record type.
2903 It has a single discrete discriminant with a default value.
2905 The component list consists of a single variant part.
2907 Each variant has a component list with a single component.
2909 No nested variants are allowed.
2911 No component has an explicit default value.
2913 No component has a non-static constraint.
2916 In addition, given a type that meets the above requirements, the
2917 following restrictions apply to its use throughout the program:
2921 The discriminant name can be mentioned only in an aggregate.
2923 No subtypes may be created of this type.
2925 The type may not be constrained by giving a discriminant value.
2927 The type cannot be passed as the actual for a generic formal with a
2931 Equality and inequality operations on @code{unchecked_unions} are not
2932 available, since there is no discriminant to compare and the compiler
2933 does not even know how many bits to compare. It is implementation
2934 dependent whether this is detected at compile time as an illegality or
2935 whether it is undetected and considered to be an erroneous construct. In
2936 GNAT, a direct comparison is illegal, but GNAT does not attempt to catch
2937 the composite case (where two composites are compared that contain an
2938 unchecked union component), so such comparisons are simply considered
2941 The layout of the resulting type corresponds exactly to a C union, where
2942 each branch of the union corresponds to a single variant in the Ada
2943 record. The semantics of the Ada program is not changed in any way by
2944 the pragma, i.e.@: provided the above restrictions are followed, and no
2945 erroneous incorrect references to fields or erroneous comparisons occur,
2946 the semantics is exactly as described by the Ada reference manual.
2947 Pragma @code{Suppress (Discriminant_Check)} applies implicitly to the
2948 type and the default convention is C
2950 @findex Unimplemented_Unit
2951 @item pragma Unimplemented_Unit
2956 pragma Unimplemented_Unit;
2960 If this pragma occurs in a unit that is processed by the compiler, GNAT
2961 aborts with the message @samp{@var{xxx} not implemented}, where
2962 @var{xxx} is the name of the current compilation unit. This pragma is
2963 intended to allow the compiler to handle unimplemented library units in
2966 The abort only happens if code is being generated. Thus you can use
2967 specs of unimplemented packages in syntax or semantic checking mode.
2969 @findex Unreferenced
2970 @item pragma Unreferenced
2971 @cindex Warnings, unreferenced
2976 pragma Unreferenced (local_Name @{, local_Name@});
2980 This pragma signals that the entities whose names are listed are
2981 deliberately not referenced. This suppresses warnings about the
2982 entities being unreferenced, and in addition a warning will be
2983 generated if one of these entities is in fact referenced.
2985 This is particularly useful for clearly signalling that a particular
2986 parameter is not referenced in some particular subprogram implementation
2987 and that this is deliberate. It can also be useful in the case of
2988 objects declared only for their initialization or finalization side
2991 If @code{local_Name} identifies more than one matching homonym in the
2992 current scope, then the entity most recently declared is the one to which
2995 @findex Unreserve_All_Interrupts
2996 @item pragma Unreserve_All_Interrupts
3001 pragma Unreserve_All_Interrupts;
3005 Normally certain interrupts are reserved to the implementation. Any attempt
3006 to attach an interrupt causes Program_Error to be raised, as described in
3007 RM C.3.2(22). A typical example is the @code{SIGINT} interrupt used in
3008 many systems for an @kbd{Ctrl-C} interrupt. Normally this interrupt is
3009 reserved to the implementation, so that @kbd{Ctrl-C} can be used to
3010 interrupt execution.
3012 If the pragma @code{Unreserve_All_Interrupts} appears anywhere in any unit in
3013 a program, then all such interrupts are unreserved. This allows the
3014 program to handle these interrupts, but disables their standard
3015 functions. For example, if this pragma is used, then pressing
3016 @kbd{Ctrl-C} will not automatically interrupt execution. However,
3017 a program can then handle the @code{SIGINT} interrupt as it chooses.
3019 For a full list of the interrupts handled in a specific implementation,
3020 see the source code for the specification of @code{Ada.Interrupts.Names} in
3021 file @file{a-intnam.ads}. This is a target dependent file that contains the
3022 list of interrupts recognized for a given target. The documentation in
3023 this file also specifies what interrupts are affected by the use of
3024 the @code{Unreserve_All_Interrupts} pragma.
3027 @item pragma Unsuppress
3032 pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
3036 This pragma undoes the effect of a previous pragma @code{Suppress}. If
3037 there is no corresponding pragma @code{Suppress} in effect, it has no
3038 effect. The range of the effect is the same as for pragma
3039 @code{Suppress}. The meaning of the arguments is identical to that used
3040 in pragma @code{Suppress}.
3042 One important application is to ensure that checks are on in cases where
3043 code depends on the checks for its correct functioning, so that the code
3044 will compile correctly even if the compiler switches are set to suppress
3047 @cindex @code{Size}, VADS compatibility
3048 @findex Use_VADS_Size
3049 @item pragma Use_VADS_Size
3054 pragma Use_VADS_Size;
3058 This is a configuration pragma. In a unit to which it applies, any use
3059 of the 'Size attribute is automatically interpreted as a use of the
3060 'VADS_Size attribute. Note that this may result in incorrect semantic
3061 processing of valid Ada 95 programs. This is intended to aid in the
3062 handling of legacy code which depends on the interpretation of Size
3063 as implemented in the VADS compiler. See description of the VADS_Size
3064 attribute for further details.
3066 @findex Validity_Checks
3067 @item pragma Validity_Checks
3072 pragma Validity_Checks (string_LITERAL | ALL_CHECKS | On | Off);
3076 This pragma is used in conjunction with compiler switches to control the
3077 built in validity checking provided by GNAT@. The compiler switches, if set
3078 provide an initial setting for the switches, and this pragma may be used
3079 to modify these settings, or the settings may be provided entirely by
3080 the use of the pragma. This pragma can be used anywhere that a pragma
3081 is legal, including use as a configuration pragma (including use in
3082 the @file{gnat.adc} file).
3084 The form with a string literal specifies which validity options are to be
3085 activated. The validity checks are first set to include only the default
3086 reference manual settings, and then a string of letters in the string
3087 specifies the exact set of options required. The form of this string
3088 is exactly as described for the @code{-gnatVx} compiler switch (see the
3089 GNAT users guide for details). For example the following two methods
3090 can be used to enable validity checking for mode @code{in} and
3091 @code{in out} subprogram parameters:
3094 pragma Validity_Checks ("im");
3095 gcc -c -gnatVim @dots{}
3099 The form ALL_CHECKS activates all standard checks (its use is equivalent
3100 to the use of the @code{gnatva} switch.
3102 The forms with @code{Off} and @code{On}
3103 can be used to temporarily disable validity checks
3104 as shown in the following example:
3110 pragma Validity_Checks ("c"); -- validity checks for copies
3111 pragma Validity_Checks (Off); -- turn off validity checks
3112 A := B; -- B will not be validity checked
3113 pragma Validity_Checks (On); -- turn validity checks back on
3114 A := C; -- C will be validity checked
3118 @item pragma Volatile
3123 pragma Volatile (local_NAME)
3127 This pragma is defined by the Ada 95 Reference Manual, and the GNAT
3128 implementation is fully conformant with this definition. The reason it
3129 is mentioned in this section is that a pragma of the same name was supplied
3130 in some Ada 83 compilers, including DEC Ada 83. The Ada 95 implementation
3131 of pragma Volatile is upwards compatible with the implementation in
3135 @item pragma Warnings
3140 pragma Warnings (On | Off [, LOCAL_NAME]);
3144 Normally warnings are enabled, with the output being controlled by
3145 the command line switch. Warnings (@code{Off}) turns off generation of
3146 warnings until a Warnings (@code{On}) is encountered or the end of the
3147 current unit. If generation of warnings is turned off using this
3148 pragma, then no warning messages are output, regardless of the
3149 setting of the command line switches.
3151 The form with a single argument is a configuration pragma.
3153 If the @var{local_name} parameter is present, warnings are suppressed for
3154 the specified entity. This suppression is effective from the point where
3155 it occurs till the end of the extended scope of the variable (similar to
3156 the scope of @code{Suppress}).
3158 @findex Weak_External
3159 @item pragma Weak_External
3164 pragma Weak_External ([Entity =>] LOCAL_NAME);
3168 This pragma specifies that the given entity should be marked as a weak
3169 external (one that does not have to be resolved) for the linker. For
3170 further details, consult the GCC manual.
3173 @node Implementation Defined Attributes
3174 @chapter Implementation Defined Attributes
3175 Ada 95 defines (throughout the Ada 95 reference manual,
3176 summarized in annex K),
3177 a set of attributes that provide useful additional functionality in all
3178 areas of the language. These language defined attributes are implemented
3179 in GNAT and work as described in the Ada 95 Reference Manual.
3181 In addition, Ada 95 allows implementations to define additional
3182 attributes whose meaning is defined by the implementation. GNAT provides
3183 a number of these implementation-dependent attributes which can be used
3184 to extend and enhance the functionality of the compiler. This section of
3185 the GNAT reference manual describes these additional attributes.
3187 Note that any program using these attributes may not be portable to
3188 other compilers (although GNAT implements this set of attributes on all
3189 platforms). Therefore if portability to other compilers is an important
3190 consideration, you should minimize the use of these attributes.
3193 @findex Abort_Signal
3196 @code{Standard'Abort_Signal} (@code{Standard} is the only allowed
3197 prefix) provides the entity for the special exception used to signal
3198 task abort or asynchronous transfer of control. Normally this attribute
3199 should only be used in the tasking runtime (it is highly peculiar, and
3200 completely outside the normal semantics of Ada, for a user program to
3201 intercept the abort exception).
3203 @cindex Size of @code{Address}
3204 @findex Address_Size
3207 @code{Standard'Address_Size} (@code{Standard} is the only allowed
3208 prefix) is a static constant giving the number of bits in an
3209 @code{Address}. It is used primarily for constructing the definition of
3210 @code{Memory_Size} in package @code{Standard}, but may be freely used in user
3211 programs and has the advantage of being static, while a direct
3212 reference to System.Address'Size is non-static because Address
3218 The @code{Asm_Input} attribute denotes a function that takes two
3219 parameters. The first is a string, the second is an expression of the
3220 type designated by the prefix. The first (string) argument is required
3221 to be a static expression, and is the constraint for the parameter,
3222 (e.g.@: what kind of register is required). The second argument is the
3223 value to be used as the input argument. The possible values for the
3224 constant are the same as those used in the RTL, and are dependent on
3225 the configuration file used to built the GCC back end.
3226 @ref{Machine Code Insertions}
3231 The @code{Asm_Output} attribute denotes a function that takes two
3232 parameters. The first is a string, the second is the name of a variable
3233 of the type designated by the attribute prefix. The first (string)
3234 argument is required to be a static expression and designates the
3235 constraint for the parameter (e.g.@: what kind of register is
3236 required). The second argument is the variable to be updated with the
3237 result. The possible values for constraint are the same as those used in
3238 the RTL, and are dependent on the configuration file used to build the
3239 GCC back end. If there are no output operands, then this argument may
3240 either be omitted, or explicitly given as @code{No_Output_Operands}.
3241 @ref{Machine Code Insertions}
3247 This attribute is implemented only in OpenVMS versions of GNAT@. Applied to
3248 the name of an entry, it yields a value of the predefined type AST_Handler
3249 (declared in the predefined package System, as extended by the use of
3250 pragma @code{Extend_System (Aux_DEC)}). This value enables the given entry to
3251 be called when an AST occurs. For further details, refer to the @cite{DEC Ada
3252 Language Reference Manual}, section 9.12a.
3256 @code{@var{obj}'Bit}, where @var{obj} is any object, yields the bit
3257 offset within the storage unit (byte) that contains the first bit of
3258 storage allocated for the object. The value of this attribute is of the
3259 type @code{Universal_Integer}, and is always a non-negative number not
3260 exceeding the value of @code{System.Storage_Unit}.
3262 For an object that is a variable or a constant allocated in a register,
3263 the value is zero. (The use of this attribute does not force the
3264 allocation of a variable to memory).
3266 For an object that is a formal parameter, this attribute applies
3267 to either the matching actual parameter or to a copy of the
3268 matching actual parameter.
3270 For an access object the value is zero. Note that
3271 @code{@var{obj}.all'Bit} is subject to an @code{Access_Check} for the
3272 designated object. Similarly for a record component
3273 @code{@var{X}.@var{C}'Bit} is subject to a discriminant check and
3274 @code{@var{X}(@var{I}).Bit} and @code{@var{X}(@var{I1}..@var{I2})'Bit}
3275 are subject to index checks.
3277 This attribute is designed to be compatible with the DEC Ada 83 definition
3278 and implementation of the @code{Bit} attribute.
3280 @findex Bit_Position
3283 @code{@var{R.C}'Bit}, where @var{R} is a record object and C is one
3284 of the fields of the record type, yields the bit
3285 offset within the record contains the first bit of
3286 storage allocated for the object. The value of this attribute is of the
3287 type @code{Universal_Integer}. The value depends only on the field
3288 @var{C} and is independent of the alignment of
3289 the containing record @var{R}.
3291 @findex Code_Address
3292 @cindex Subprogram address
3293 @cindex Address of subprogram code
3297 attribute may be applied to subprograms in Ada 95, but the
3298 intended effect from the Ada 95 reference manual seems to be to provide
3299 an address value which can be used to call the subprogram by means of
3300 an address clause as in the following example:
3303 procedure K is @dots{}
3306 for L'Address use K'Address;
3307 pragma Import (Ada, L);
3311 A call to @code{L} is then expected to result in a call to @code{K}@. In Ada 83, where
3312 there were no access-to-subprogram values, this was a common work around
3313 for getting the effect of an indirect call.
3314 GNAT implements the above use of @code{Address} and the technique illustrated
3315 by the example code works correctly.
3317 However, for some purposes, it is useful to have the address of the start
3318 of the generated code for the subprogram. On some architectures, this is
3319 not necessarily the same as the @code{Address} value described above. For example,
3320 the @code{Address} value may reference a subprogram descriptor rather than the
3323 The @code{'Code_Address} attribute, which can only be applied to
3324 subprogram entities, always returns the address of the start of the
3325 generated code of the specified subprogram, which may or may not be
3326 the same value as is returned by the corresponding @code{'Address}
3330 @cindex Little endian
3331 @findex Default_Bit_Order
3332 @item Default_Bit_Order
3334 @code{Standard'Default_Bit_Order} (@code{Standard} is the only
3335 permissible prefix), provides the value @code{System.Default_Bit_Order}
3336 as a @code{Pos} value (0 for @code{High_Order_First}, 1 for
3337 @code{Low_Order_First}). This is used to construct the definition of
3338 @code{Default_Bit_Order} in package @code{System}.
3343 The prefix of the @code{'Elaborated} attribute must be a unit name. The
3344 value is a Boolean which indicates whether or not the given unit has been
3345 elaborated. This attribute is primarily intended for internal use by the
3346 generated code for dynamic elaboration checking, but it can also be used
3347 in user programs. The value will always be True once elaboration of all
3348 units has been completed.
3353 This attribute can only be applied to a program unit name. It returns
3354 the entity for the corresponding elaboration procedure for elaborating
3355 the body of the referenced unit. This is used in the main generated
3356 elaboration procedure by the binder and is not normally used in any
3357 other context. However, there may be specialized situations in which it
3358 is useful to be able to call this elaboration procedure from Ada code,
3359 e.g.@: if it is necessary to do selective re-elaboration to fix some
3365 This attribute can only be applied to a program unit name. It returns
3366 the entity for the corresponding elaboration procedure for elaborating
3367 the specification of the referenced unit. This is used in the main
3368 generated elaboration procedure by the binder and is not normally used
3369 in any other context. However, there may be specialized situations in
3370 which it is useful to be able to call this elaboration procedure from
3371 Ada code, e.g.@: if it is necessary to do selective re-elaboration to fix
3374 @cindex Ada 83 attributes
3378 The @code{Emax} attribute is provided for compatibility with Ada 83. See
3379 the Ada 83 reference manual for an exact description of the semantics of
3382 @cindex Representation of enums
3386 For every enumeration subtype @var{S}, @code{@var{S}'Enum_Rep} denotes a
3387 function with the following specification:
3390 function @var{S}'Enum_Rep (Arg : @var{S}'Base)
3391 return Universal_Integer;
3395 It is also allowable to apply @code{Enum_Rep} directly to an object of an
3396 enumeration type or to a non-overloaded enumeration
3397 literal. In this case @code{@var{S}'Enum_Rep} is equivalent to
3398 @code{@var{typ}'Enum_Rep(@var{S})} where @var{typ} is the type of the
3399 enumeration literal or object.
3401 The function returns the representation value for the given enumeration
3402 value. This will be equal to value of the @code{Pos} attribute in the
3403 absence of an enumeration representation clause. This is a static
3404 attribute (i.e.@: the result is static if the argument is static).
3406 @code{@var{S}'Enum_Rep} can also be used with integer types and objects, in which
3407 case it simply returns the integer value. The reason for this is to allow
3408 it to be used for @code{(<>)} discrete formal arguments in a generic unit that
3409 can be instantiated with either enumeration types or integer types. Note
3410 that if @code{Enum_Rep} is used on a modular type whose upper bound exceeds the
3411 upper bound of the largest signed integer type, and the argument is a
3412 variable, so that the universal integer calculation is done at run-time,
3413 then the call to @code{Enum_Rep} may raise @code{Constraint_Error}.
3415 @cindex Ada 83 attributes
3419 The @code{Epsilon} attribute is provided for compatibility with Ada 83. See
3420 the Ada 83 reference manual for an exact description of the semantics of
3426 For every fixed-point type @var{S}, @code{@var{S}'Fixed_Value} denotes a
3427 function with the following specification:
3430 function @var{S}'Fixed_Value (Arg : Universal_Integer)
3435 The value returned is the fixed-point value @var{V} such that
3438 @var{V} = Arg * @var{S}'Small
3442 The effect is thus equivalent to first converting the argument to the
3443 integer type used to represent @var{S}, and then doing an unchecked
3444 conversion to the fixed-point type. This attribute is primarily intended
3445 for use in implementation of the input-output functions for fixed-point
3448 @cindex Discriminants, testing for
3449 @findex Has_Discriminants
3450 @item Has_Discriminants
3452 The prefix of the @code{Has_Discriminants} attribute is a type. The result
3453 is a Boolean value which is True if the type has discriminants, and False
3454 otherwise. The intended use of this attribute is in conjunction with generic
3455 definitions. If the attribute is applied to a generic private type, it
3456 indicates whether or not the corresponding actual type has discriminants.
3461 The @code{Img} attribute differs from @code{Image} in that it may be
3462 applied to objects as well as types, in which case it gives the
3463 @code{Image} for the subtype of the object. This is convenient for
3467 Put_Line ("X = " & X'Img);
3471 has the same meaning as the more verbose:
3474 Put_Line ("X = " & @var{type}'Image (X));
3477 where @var{type} is the subtype of the object X@.
3479 @findex Integer_Value
3482 For every integer type @var{S}, @code{@var{S}'Integer_Value} denotes a
3483 function with the following specification:
3486 function @var{S}'Integer_Value (Arg : Universal_Fixed)
3491 The value returned is the integer value @var{V}, such that
3494 Arg = @var{V} * @var{type}'Small
3498 The effect is thus equivalent to first doing an unchecked convert from
3499 the fixed-point type to its corresponding implementation type, and then
3500 converting the result to the target integer type. This attribute is
3501 primarily intended for use in implementation of the standard
3502 input-output functions for fixed-point values.
3504 @cindex Ada 83 attributes
3508 The @code{Large} attribute is provided for compatibility with Ada 83. See
3509 the Ada 83 reference manual for an exact description of the semantics of
3512 @findex Machine_Size
3515 This attribute is identical to the @code{Object_Size} attribute. It is
3516 provided for compatibility with the DEC Ada 83 attribute of this name.
3518 @cindex Ada 83 attributes
3522 The @code{Mantissa} attribute is provided for compatibility with Ada 83. See
3523 the Ada 83 reference manual for an exact description of the semantics of
3526 @cindex Interrupt priority, maximum
3527 @findex Max_Interrupt_Priority
3528 @item Max_Interrupt_Priority
3530 @code{Standard'Max_Interrupt_Priority} (@code{Standard} is the only
3531 permissible prefix), provides the value
3532 @code{System.Max_Interrupt_Priority} and is intended primarily for
3533 constructing this definition in package @code{System}.
3535 @cindex Priority, maximum
3536 @findex Max_Priority
3539 @code{Standard'Max_Priority} (@code{Standard} is the only permissible
3540 prefix) provides the value @code{System.Max_Priority} and is intended
3541 primarily for constructing this definition in package @code{System}.
3543 @cindex Alignment, maximum
3544 @findex Maximum_Alignment
3545 @item Maximum_Alignment
3547 @code{Standard'Maximum_Alignment} (@code{Standard} is the only
3548 permissible prefix) provides the maximum useful alignment value for the
3549 target. This is a static value that can be used to specify the alignment
3550 for an object, guaranteeing that it is properly aligned in all
3551 cases. This is useful when an external object is imported and its
3552 alignment requirements are unknown.
3554 @cindex Return values, passing mechanism
3555 @cindex Parameters, passing mechanism
3556 @findex Mechanism_Code
3557 @item Mechanism_Code
3559 @code{@var{function}'Mechanism_Code} yields an integer code for the
3560 mechanism used for the result of function, and
3561 @code{@var{subprogram}'Mechanism_Code (@var{n})} yields the mechanism
3562 used for formal parameter number @var{n} (a static integer value with 1
3563 meaning the first parameter) of @var{subprogram}. The code returned is:
3571 by descriptor (default descriptor class)
3573 by descriptor (UBS: unaligned bit string)
3575 by descriptor (UBSB: aligned bit string with arbitrary bounds)
3577 by descriptor (UBA: unaligned bit array)
3579 by descriptor (S: string, also scalar access type parameter)
3581 by descriptor (SB: string with arbitrary bounds)
3583 by descriptor (A: contiguous array)
3585 by descriptor (NCA: non-contiguous array)
3589 Values from 3 through 10 are only relevant to Digital OpenVMS implementations.
3591 @cindex Zero address, passing
3592 @findex Null_Parameter
3593 @item Null_Parameter
3595 A reference @code{@var{T}'Null_Parameter} denotes an imaginary object of
3596 type or subtype @var{T} allocated at machine address zero. The attribute
3597 is allowed only as the default expression of a formal parameter, or as
3598 an actual expression of a subprogram call. In either case, the
3599 subprogram must be imported.
3601 The identity of the object is represented by the address zero in the
3602 argument list, independent of the passing mechanism (explicit or
3605 This capability is needed to specify that a zero address should be
3606 passed for a record or other composite object passed by reference.
3607 There is no way of indicating this without the @code{Null_Parameter}
3610 @cindex Size, used for objects
3614 The size of an object is not necessarily the same as the size of the type
3615 of an object. This is because by default object sizes are increased to be
3616 a multiple of the alignment of the object. For example,
3617 @code{Natural'Size} is
3618 31, but by default objects of type @code{Natural} will have a size of 32 bits.
3619 Similarly, a record containing an integer and a character:
3629 will have a size of 40 (that is @code{Rec'Size} will be 40. The
3630 alignment will be 4, because of the
3631 integer field, and so the default size of record objects for this type
3632 will be 64 (8 bytes).
3634 The @code{@var{type}'Object_Size} attribute
3635 has been added to GNAT to allow the
3636 default object size of a type to be easily determined. For example,
3637 @code{Natural'Object_Size} is 32, and
3638 @code{Rec'Object_Size} (for the record type in the above example) will be
3639 64. Note also that, unlike the situation with the
3640 @code{Size} attribute as defined in the Ada RM, the
3641 @code{Object_Size} attribute can be specified individually
3642 for different subtypes. For example:
3645 type R is new Integer;
3646 subtype R1 is R range 1 .. 10;
3647 subtype R2 is R range 1 .. 10;
3648 for R2'Object_Size use 8;
3652 In this example, @code{R'Object_Size} and @code{R1'Object_Size} are both
3653 32 since the default object size for a subtype is the same as the object size
3654 for the parent subtype. This means that objects of type @code{R}
3656 by default be 32 bits (four bytes). But objects of type
3657 @code{R2} will be only
3658 8 bits (one byte), since @code{R2'Object_Size} has been set to 8.
3660 @cindex Parameters, when passed by reference
3661 @findex Passed_By_Reference
3662 @item Passed_By_Reference
3664 @code{@var{type}'Passed_By_Reference} for any subtype @var{type} returns
3665 a value of type @code{Boolean} value that is @code{True} if the type is
3666 normally passed by reference and @code{False} if the type is normally
3667 passed by copy in calls. For scalar types, the result is always @code{False}
3668 and is static. For non-scalar types, the result is non-static.
3670 @findex Range_Length
3673 @code{@var{type}'Range_Length} for any discrete type @var{type} yields
3674 the number of values represented by the subtype (zero for a null
3675 range). The result is static for static subtypes. @code{Range_Length}
3676 applied to the index subtype of a one dimensional array always gives the
3677 same result as @code{Range} applied to the array itself.
3679 @cindex Ada 83 attributes
3683 The @code{Safe_Emax} attribute is provided for compatibility with Ada 83. See
3684 the Ada 83 reference manual for an exact description of the semantics of
3687 @cindex Ada 83 attributes
3691 The @code{Safe_Large} attribute is provided for compatibility with Ada 83. See
3692 the Ada 83 reference manual for an exact description of the semantics of
3695 @cindex Ada 83 attributes
3699 The @code{Safe_Large} attribute is provided for compatibility with Ada 83. See
3700 the Ada 83 reference manual for an exact description of the semantics of
3703 @cindex Ada 83 attributes
3707 The @code{Small} attribute is defined in Ada 95 only for fixed-point types.
3708 GNAT also allows this attribute to be applied to floating-point types
3709 for compatibility with Ada 83. See
3710 the Ada 83 reference manual for an exact description of the semantics of
3711 this attribute when applied to floating-point types.
3713 @findex Storage_Unit
3716 @code{Standard'Storage_Unit} (@code{Standard} is the only permissible
3717 prefix) provides the value @code{System.Storage_Unit} and is intended
3718 primarily for constructing this definition in package @code{System}.
3723 @code{Standard'Tick} (@code{Standard} is the only permissible prefix)
3724 provides the value of @code{System.Tick} and is intended primarily for
3725 constructing this definition in package @code{System}.
3730 The @code{System'To_Address}
3731 (@code{System} is the only permissible prefix)
3732 denotes a function identical to
3733 @code{System.Storage_Elements.To_Address} except that
3734 it is a static attribute. This means that if its argument is
3735 a static expression, then the result of the attribute is a
3736 static expression. The result is that such an expression can be
3737 used in contexts (e.g.@: preelaborable packages) which require a
3738 static expression and where the function call could not be used
3739 (since the function call is always non-static, even if its
3740 argument is static).
3745 @code{@var{type}'Type_Class} for any type or subtype @var{type} yields
3746 the value of the type class for the full type of @var{type}. If
3747 @var{type} is a generic formal type, the value is the value for the
3748 corresponding actual subtype. The value of this attribute is of type
3749 @code{System.Aux_DEC.Type_Class}, which has the following definition:
3753 (Type_Class_Enumeration,
3755 Type_Class_Fixed_Point,
3756 Type_Class_Floating_Point,
3761 Type_Class_Address);
3765 Protected types yield the value @code{Type_Class_Task}, which thus
3766 applies to all concurrent types. This attribute is designed to
3767 be compatible with the DEC Ada 83 attribute of the same name.
3772 The @code{UET_Address} attribute can only be used for a prefix which
3773 denotes a library package. It yields the address of the unit exception
3774 table when zero cost exception handling is used. This attribute is
3775 intended only for use within the GNAT implementation. See the unit
3776 @code{Ada.Exceptions} in files @file{a-except.ads} and @file{a-except.adb}
3777 for details on how this attribute is used in the implementation.
3779 @cindex Named numbers, representation of
3780 @findex Universal_Literal_String
3781 @item Universal_Literal_String
3783 The prefix of @code{Universal_Literal_String} must be a named
3784 number. The static result is the string consisting of the characters of
3785 the number as defined in the original source. This allows the user
3786 program to access the actual text of named numbers without intermediate
3787 conversions and without the need to enclose the strings in quotes (which
3788 would preclude their use as numbers). This is used internally for the
3789 construction of values of the floating-point attributes from the file
3790 @file{ttypef.ads}, but may also be used by user programs.
3792 @cindex @code{Access}, unrestricted
3793 @findex Unrestricted_Access
3794 @item Unrestricted_Access
3796 The @code{Unrestricted_Access} attribute is similar to @code{Access}
3797 except that all accessibility and aliased view checks are omitted. This
3798 is a user-beware attribute. It is similar to
3799 @code{Address}, for which it is a desirable replacement where the value
3800 desired is an access type. In other words, its effect is identical to
3801 first applying the @code{Address} attribute and then doing an unchecked
3802 conversion to a desired access type. In GNAT, but not necessarily in
3803 other implementations, the use of static chains for inner level
3804 subprograms means that @code{Unrestricted_Access} applied to a
3805 subprogram yields a value that can be called as long as the subprogram
3806 is in scope (normal Ada 95 accessibility rules restrict this usage).
3808 @cindex @code{Size}, VADS compatibility
3812 The @code{'VADS_Size} attribute is intended to make it easier to port
3813 legacy code which relies on the semantics of @code{'Size} as implemented
3814 by the VADS Ada 83 compiler. GNAT makes a best effort at duplicating the
3815 same semantic interpretation. In particular, @code{'VADS_Size} applied
3816 to a predefined or other primitive type with no Size clause yields the
3817 Object_Size (for example, @code{Natural'Size} is 32 rather than 31 on
3818 typical machines). In addition @code{'VADS_Size} applied to an object
3819 gives the result that would be obtained by applying the attribute to
3820 the corresponding type.
3822 @cindex @code{Size}, setting for not-first subtype
3825 @code{@var{type}'Value_Size} is the number of bits required to represent
3826 a value of the given subtype. It is the same as @code{@var{type}'Size},
3827 but, unlike @code{Size}, may be set for non-first subtypes.
3829 @findex Wchar_T_Size
3831 @code{Standard'Wchar_T_Size} (@code{Standard} is the only permissible
3832 prefix) provides the size in bits of the C @code{wchar_t} type
3833 primarily for constructing the definition of this type in
3834 package @code{Interfaces.C}.
3838 @code{Standard'Word_Size} (@code{Standard} is the only permissible
3839 prefix) provides the value @code{System.Word_Size} and is intended
3840 primarily for constructing this definition in package @code{System}.
3842 @node Implementation Advice
3843 @chapter Implementation Advice
3844 The main text of the Ada 95 Reference Manual describes the required
3845 behavior of all Ada 95 compilers, and the GNAT compiler conforms to
3848 In addition, there are sections throughout the Ada 95
3849 reference manual headed
3850 by the phrase ``implementation advice''. These sections are not normative,
3851 i.e.@: they do not specify requirements that all compilers must
3852 follow. Rather they provide advice on generally desirable behavior. You
3853 may wonder why they are not requirements. The most typical answer is
3854 that they describe behavior that seems generally desirable, but cannot
3855 be provided on all systems, or which may be undesirable on some systems.
3857 As far as practical, GNAT follows the implementation advice sections in
3858 the Ada 95 Reference Manual. This chapter contains a table giving the
3859 reference manual section number, paragraph number and several keywords
3860 for each advice. Each entry consists of the text of the advice followed
3861 by the GNAT interpretation of this advice. Most often, this simply says
3862 ``followed'', which means that GNAT follows the advice. However, in a
3863 number of cases, GNAT deliberately deviates from this advice, in which
3864 case the text describes what GNAT does and why.
3867 @cindex Error detection
3868 @item 1.1.3(20): Error Detection
3871 If an implementation detects the use of an unsupported Specialized Needs
3872 Annex feature at run time, it should raise @code{Program_Error} if
3875 Not relevant. All specialized needs annex features are either supported,
3876 or diagnosed at compile time.
3879 @item 1.1.3(31): Child Units
3882 If an implementation wishes to provide implementation-defined
3883 extensions to the functionality of a language-defined library unit, it
3884 should normally do so by adding children to the library unit.
3888 @cindex Bounded errors
3889 @item 1.1.5(12): Bounded Errors
3892 If an implementation detects a bounded error or erroneous
3893 execution, it should raise @code{Program_Error}.
3895 Followed in all cases in which the implementation detects a bounded
3896 error or erroneous execution. Not all such situations are detected at
3900 @item 2.8(16): Pragmas
3903 Normally, implementation-defined pragmas should have no semantic effect
3904 for error-free programs; that is, if the implementation-defined pragmas
3905 are removed from a working program, the program should still be legal,
3906 and should still have the same semantics.
3908 The following implementation defined pragmas are exceptions to this
3920 @item CPP_Constructor
3928 @item Interface_Name
3930 @item Machine_Attribute
3932 @item Unimplemented_Unit
3934 @item Unchecked_Union
3938 In each of the above cases, it is essential to the purpose of the pragma
3939 that this advice not be followed. For details see the separate section
3940 on implementation defined pragmas.
3942 @item 2.8(17-19): Pragmas
3945 Normally, an implementation should not define pragmas that can
3946 make an illegal program legal, except as follows:
3950 A pragma used to complete a declaration, such as a pragma @code{Import};
3954 A pragma used to configure the environment by adding, removing, or
3955 replacing @code{library_items}.
3957 See response to paragraph 16 of this same section.
3959 @cindex Character Sets
3960 @cindex Alternative Character Sets
3961 @item 3.5.2(5): Alternative Character Sets
3964 If an implementation supports a mode with alternative interpretations
3965 for @code{Character} and @code{Wide_Character}, the set of graphic
3966 characters of @code{Character} should nevertheless remain a proper
3967 subset of the set of graphic characters of @code{Wide_Character}. Any
3968 character set ``localizations'' should be reflected in the results of
3969 the subprograms defined in the language-defined package
3970 @code{Characters.Handling} (see A.3) available in such a mode. In a mode with
3971 an alternative interpretation of @code{Character}, the implementation should
3972 also support a corresponding change in what is a legal
3973 @code{identifier_letter}.
3975 Not all wide character modes follow this advice, in particular the JIS
3976 and IEC modes reflect standard usage in Japan, and in these encoding,
3977 the upper half of the Latin-1 set is not part of the wide-character
3978 subset, since the most significant bit is used for wide character
3979 encoding. However, this only applies to the external forms. Internally
3980 there is no such restriction.
3982 @cindex Integer types
3983 @item 3.5.4(28): Integer Types
3987 An implementation should support @code{Long_Integer} in addition to
3988 @code{Integer} if the target machine supports 32-bit (or longer)
3989 arithmetic. No other named integer subtypes are recommended for package
3990 @code{Standard}. Instead, appropriate named integer subtypes should be
3991 provided in the library package @code{Interfaces} (see B.2).
3993 @code{Long_Integer} is supported. Other standard integer types are supported
3994 so this advice is not fully followed. These types
3995 are supported for convenient interface to C, and so that all hardware
3996 types of the machine are easily available.
3997 @item 3.5.4(29): Integer Types
4001 An implementation for a two's complement machine should support
4002 modular types with a binary modulus up to @code{System.Max_Int*2+2}. An
4003 implementation should support a non-binary modules up to @code{Integer'Last}.
4007 @cindex Enumeration values
4008 @item 3.5.5(8): Enumeration Values
4011 For the evaluation of a call on @code{@var{S}'Pos} for an enumeration
4012 subtype, if the value of the operand does not correspond to the internal
4013 code for any enumeration literal of its type (perhaps due to an
4014 un-initialized variable), then the implementation should raise
4015 @code{Program_Error}. This is particularly important for enumeration
4016 types with noncontiguous internal codes specified by an
4017 enumeration_representation_clause.
4022 @item 3.5.7(17): Float Types
4025 An implementation should support @code{Long_Float} in addition to
4026 @code{Float} if the target machine supports 11 or more digits of
4027 precision. No other named floating point subtypes are recommended for
4028 package @code{Standard}. Instead, appropriate named floating point subtypes
4029 should be provided in the library package @code{Interfaces} (see B.2).
4031 @code{Short_Float} and @code{Long_Long_Float} are also provided. The
4032 former provides improved compatibility with other implementations
4033 supporting this type. The latter corresponds to the highest precision
4034 floating-point type supported by the hardware. On most machines, this
4035 will be the same as @code{Long_Float}, but on some machines, it will
4036 correspond to the IEEE extended form. The notable case is all ia32
4037 (x86) implementations, where @code{Long_Long_Float} corresponds to
4038 the 80-bit extended precision format supported in hardware on this
4039 processor. Note that the 128-bit format on SPARC is not supported,
4040 since this is a software rather than a hardware format.
4042 @cindex Multidimensional arrays
4043 @cindex Arrays, multidimensional
4044 @item 3.6.2(11): Multidimensional Arrays
4047 An implementation should normally represent multidimensional arrays in
4048 row-major order, consistent with the notation used for multidimensional
4049 array aggregates (see 4.3.3). However, if a pragma @code{Convention}
4050 (@code{Fortran}, @dots{}) applies to a multidimensional array type, then
4051 column-major order should be used instead (see B.5, ``Interfacing with
4056 @findex Duration'Small
4057 @item 9.6(30-31): Duration'Small
4060 Whenever possible in an implementation, the value of @code{Duration'Small}
4061 should be no greater than 100 microseconds.
4063 Followed. (@code{Duration'Small} = 10**(@minus{}9)).
4067 The time base for @code{delay_relative_statements} should be monotonic;
4068 it need not be the same time base as used for @code{Calendar.Clock}.
4072 @item 10.2.1(12): Consistent Representation
4075 In an implementation, a type declared in a pre-elaborated package should
4076 have the same representation in every elaboration of a given version of
4077 the package, whether the elaborations occur in distinct executions of
4078 the same program, or in executions of distinct programs or partitions
4079 that include the given version.
4081 Followed, except in the case of tagged types. Tagged types involve
4082 implicit pointers to a local copy of a dispatch table, and these pointers
4083 have representations which thus depend on a particular elaboration of the
4084 package. It is not easy to see how it would be possible to follow this
4085 advice without severely impacting efficiency of execution.
4087 @cindex Exception information
4088 @item 11.4.1(19): Exception Information
4091 @code{Exception_Message} by default and @code{Exception_Information}
4092 should produce information useful for
4093 debugging. @code{Exception_Message} should be short, about one
4094 line. @code{Exception_Information} can be long. @code{Exception_Message}
4095 should not include the
4096 @code{Exception_Name}. @code{Exception_Information} should include both
4097 the @code{Exception_Name} and the @code{Exception_Message}.
4099 Followed. For each exception that doesn't have a specified
4100 @code{Exception_Message}, the compiler generates one containing the location
4101 of the raise statement. This location has the form ``file:line'', where
4102 file is the short file name (without path information) and line is the line
4103 number in the file. Note that in the case of the Zero Cost Exception
4104 mechanism, these messages become redundant with the Exception_Information that
4105 contains a full backtrace of the calling sequence, so they are disabled.
4106 To disable explicitly the generation of the source location message, use the
4107 Pragma @code{Discard_Names}.
4109 @cindex Suppression of checks
4110 @cindex Checks, suppression of
4111 @item 11.5(28): Suppression of Checks
4114 The implementation should minimize the code executed for checks that
4115 have been suppressed.
4119 @cindex Representation clauses
4120 @item 13.1 (21-24): Representation Clauses
4123 The recommended level of support for all representation items is
4124 qualified as follows:
4128 An implementation need not support representation items containing
4129 non-static expressions, except that an implementation should support a
4130 representation item for a given entity if each non-static expression in
4131 the representation item is a name that statically denotes a constant
4132 declared before the entity.
4134 Followed. GNAT does not support non-static expressions in representation
4135 clauses unless they are constants declared before the entity. For
4140 for X'Address use To_address (16#2000#);
4144 will be rejected, since the To_Address expression is non-static. Instead
4148 X_Address : constant Address : =
4149 To_Address ((16#2000#);
4151 for X'Address use X_Address;
4156 An implementation need not support a specification for the @code{Size}
4157 for a given composite subtype, nor the size or storage place for an
4158 object (including a component) of a given composite subtype, unless the
4159 constraints on the subtype and its composite subcomponents (if any) are
4160 all static constraints.
4162 Followed. Size Clauses are not permitted on non-static components, as
4167 An aliased component, or a component whose type is by-reference, should
4168 always be allocated at an addressable location.
4172 @cindex Packed types
4173 @item 13.2(6-8): Packed Types
4176 If a type is packed, then the implementation should try to minimize
4177 storage allocated to objects of the type, possibly at the expense of
4178 speed of accessing components, subject to reasonable complexity in
4179 addressing calculations.
4183 The recommended level of support pragma @code{Pack} is:
4185 For a packed record type, the components should be packed as tightly as
4186 possible subject to the Sizes of the component subtypes, and subject to
4187 any @code{record_representation_clause} that applies to the type; the
4188 implementation may, but need not, reorder components or cross aligned
4189 word boundaries to improve the packing. A component whose @code{Size} is
4190 greater than the word size may be allocated an integral number of words.
4192 Followed. Tight packing of arrays is supported for all component sizes
4197 An implementation should support Address clauses for imported
4201 @cindex @code{Address} clauses
4202 @item 13.3(14-19): Address Clauses
4206 For an array @var{X}, @code{@var{X}'Address} should point at the first
4207 component of the array, and not at the array bounds.
4213 The recommended level of support for the @code{Address} attribute is:
4215 @code{@var{X}'Address} should produce a useful result if @var{X} is an
4216 object that is aliased or of a by-reference type, or is an entity whose
4217 @code{Address} has been specified.
4219 Followed. A valid address will be produced even if none of those
4220 conditions have been met. If necessary, the object is forced into
4221 memory to ensure the address is valid.
4225 An implementation should support @code{Address} clauses for imported
4232 Objects (including subcomponents) that are aliased or of a by-reference
4233 type should be allocated on storage element boundaries.
4239 If the @code{Address} of an object is specified, or it is imported or exported,
4240 then the implementation should not perform optimizations based on
4241 assumptions of no aliases.
4245 @cindex @code{Alignment} clauses
4246 @item 13.3(29-35): Alignment Clauses
4249 The recommended level of support for the @code{Alignment} attribute for
4252 An implementation should support specified Alignments that are factors
4253 and multiples of the number of storage elements per word, subject to the
4260 An implementation need not support specified @code{Alignment}s for
4261 combinations of @code{Size}s and @code{Alignment}s that cannot be easily
4262 loaded and stored by available machine instructions.
4268 An implementation need not support specified @code{Alignment}s that are
4269 greater than the maximum @code{Alignment} the implementation ever returns by
4276 The recommended level of support for the @code{Alignment} attribute for
4279 Same as above, for subtypes, but in addition:
4285 For stand-alone library-level objects of statically constrained
4286 subtypes, the implementation should support all @code{Alignment}s
4287 supported by the target linker. For example, page alignment is likely to
4288 be supported for such objects, but not for subtypes.
4292 @cindex @code{Size} clauses
4293 @item 13.3(42-43): Size Clauses
4296 The recommended level of support for the @code{Size} attribute of
4299 A @code{Size} clause should be supported for an object if the specified
4300 @code{Size} is at least as large as its subtype's @code{Size}, and
4301 corresponds to a size in storage elements that is a multiple of the
4302 object's @code{Alignment} (if the @code{Alignment} is nonzero).
4306 @item 13.3(50-56): Size Clauses
4309 If the @code{Size} of a subtype is specified, and allows for efficient
4310 independent addressability (see 9.10) on the target architecture, then
4311 the @code{Size} of the following objects of the subtype should equal the
4312 @code{Size} of the subtype:
4314 Aliased objects (including components).
4320 @code{Size} clause on a composite subtype should not affect the
4321 internal layout of components.
4327 The recommended level of support for the @code{Size} attribute of subtypes is:
4331 The @code{Size} (if not specified) of a static discrete or fixed point
4332 subtype should be the number of bits needed to represent each value
4333 belonging to the subtype using an unbiased representation, leaving space
4334 for a sign bit only if the subtype contains negative values. If such a
4335 subtype is a first subtype, then an implementation should support a
4336 specified @code{Size} for it that reflects this representation.
4342 For a subtype implemented with levels of indirection, the @code{Size}
4343 should include the size of the pointers, but not the size of what they
4348 @cindex @code{Component_Size} clauses
4349 @item 13.3(71-73): Component Size Clauses
4352 The recommended level of support for the @code{Component_Size}
4357 An implementation need not support specified @code{Component_Sizes} that are
4358 less than the @code{Size} of the component subtype.
4364 An implementation should support specified @code{Component_Size}s that
4365 are factors and multiples of the word size. For such
4366 @code{Component_Size}s, the array should contain no gaps between
4367 components. For other @code{Component_Size}s (if supported), the array
4368 should contain no gaps between components when packing is also
4369 specified; the implementation should forbid this combination in cases
4370 where it cannot support a no-gaps representation.
4374 @cindex Enumeration representation clauses
4375 @cindex Representation clauses, enumeration
4376 @item 13.4(9-10): Enumeration Representation Clauses
4379 The recommended level of support for enumeration representation clauses
4382 An implementation need not support enumeration representation clauses
4383 for boolean types, but should at minimum support the internal codes in
4384 the range @code{System.Min_Int.System.Max_Int}.
4388 @cindex Record representation clauses
4389 @cindex Representation clauses, records
4390 @item 13.5.1(17-22): Record Representation Clauses
4393 The recommended level of support for
4394 @*@code{record_representation_clauses} is:
4396 An implementation should support storage places that can be extracted
4397 with a load, mask, shift sequence of machine code, and set with a load,
4398 shift, mask, store sequence, given the available machine instructions
4405 A storage place should be supported if its size is equal to the
4406 @code{Size} of the component subtype, and it starts and ends on a
4407 boundary that obeys the @code{Alignment} of the component subtype.
4413 If the default bit ordering applies to the declaration of a given type,
4414 then for a component whose subtype's @code{Size} is less than the word
4415 size, any storage place that does not cross an aligned word boundary
4416 should be supported.
4422 An implementation may reserve a storage place for the tag field of a
4423 tagged type, and disallow other components from overlapping that place.
4425 Followed. The storage place for the tag field is the beginning of the tagged
4426 record, and its size is Address'Size. GNAT will reject an explicit component
4427 clause for the tag field.
4431 An implementation need not support a @code{component_clause} for a
4432 component of an extension part if the storage place is not after the
4433 storage places of all components of the parent type, whether or not
4434 those storage places had been specified.
4436 Followed. The above advice on record representation clauses is followed,
4437 and all mentioned features are implemented.
4439 @cindex Storage place attributes
4440 @item 13.5.2(5): Storage Place Attributes
4443 If a component is represented using some form of pointer (such as an
4444 offset) to the actual data of the component, and this data is contiguous
4445 with the rest of the object, then the storage place attributes should
4446 reflect the place of the actual data, not the pointer. If a component is
4447 allocated discontinuously from the rest of the object, then a warning
4448 should be generated upon reference to one of its storage place
4451 Followed. There are no such components in GNAT@.
4453 @cindex Bit ordering
4454 @item 13.5.3(7-8): Bit Ordering
4457 The recommended level of support for the non-default bit ordering is:
4461 If @code{Word_Size} = @code{Storage_Unit}, then the implementation
4462 should support the non-default bit ordering in addition to the default
4465 Followed. Word size does not equal storage size in this implementation.
4466 Thus non-default bit ordering is not supported.
4468 @cindex @code{Address}, as private type
4469 @item 13.7(37): Address as Private
4472 @code{Address} should be of a private type.
4476 @cindex Operations, on @code{Address}
4477 @cindex @code{Address}, operations of
4478 @item 13.7.1(16): Address Operations
4481 Operations in @code{System} and its children should reflect the target
4482 environment semantics as closely as is reasonable. For example, on most
4483 machines, it makes sense for address arithmetic to ``wrap around''.
4484 Operations that do not make sense should raise @code{Program_Error}.
4486 Followed. Address arithmetic is modular arithmetic that wraps around. No
4487 operation raises @code{Program_Error}, since all operations make sense.
4489 @cindex Unchecked conversion
4490 @item 13.9(14-17): Unchecked Conversion
4493 The @code{Size} of an array object should not include its bounds; hence,
4494 the bounds should not be part of the converted data.
4500 The implementation should not generate unnecessary run-time checks to
4501 ensure that the representation of @var{S} is a representation of the
4502 target type. It should take advantage of the permission to return by
4503 reference when possible. Restrictions on unchecked conversions should be
4504 avoided unless required by the target environment.
4506 Followed. There are no restrictions on unchecked conversion. A warning is
4507 generated if the source and target types do not have the same size since
4508 the semantics in this case may be target dependent.
4512 The recommended level of support for unchecked conversions is:
4516 Unchecked conversions should be supported and should be reversible in
4517 the cases where this clause defines the result. To enable meaningful use
4518 of unchecked conversion, a contiguous representation should be used for
4519 elementary subtypes, for statically constrained array subtypes whose
4520 component subtype is one of the subtypes described in this paragraph,
4521 and for record subtypes without discriminants whose component subtypes
4522 are described in this paragraph.
4526 @cindex Heap usage, implicit
4527 @item 13.11(23-25): Implicit Heap Usage
4530 An implementation should document any cases in which it dynamically
4531 allocates heap storage for a purpose other than the evaluation of an
4534 Followed, the only other points at which heap storage is dynamically
4535 allocated are as follows:
4539 At initial elaboration time, to allocate dynamically sized global
4543 To allocate space for a task when a task is created.
4546 To extend the secondary stack dynamically when needed. The secondary
4547 stack is used for returning variable length results.
4552 A default (implementation-provided) storage pool for an
4553 access-to-constant type should not have overhead to support deallocation of
4560 A storage pool for an anonymous access type should be created at the
4561 point of an allocator for the type, and be reclaimed when the designated
4562 object becomes inaccessible.
4566 @cindex Unchecked deallocation
4567 @item 13.11.2(17): Unchecked De-allocation
4570 For a standard storage pool, @code{Free} should actually reclaim the
4575 @cindex Stream oriented attributes
4576 @item 13.13.2(17): Stream Oriented Attributes
4579 If a stream element is the same size as a storage element, then the
4580 normal in-memory representation should be used by @code{Read} and
4581 @code{Write} for scalar objects. Otherwise, @code{Read} and @code{Write}
4582 should use the smallest number of stream elements needed to represent
4583 all values in the base range of the scalar type.
4585 Followed. In particular, the interpretation chosen is that of AI-195,
4586 which specifies that the size to be used is that of the first subtype.
4588 @item A.1(52): Implementation Advice
4591 If an implementation provides additional named predefined integer types,
4592 then the names should end with @samp{Integer} as in
4593 @samp{Long_Integer}. If an implementation provides additional named
4594 predefined floating point types, then the names should end with
4595 @samp{Float} as in @samp{Long_Float}.
4599 @findex Ada.Characters.Handling
4600 @item A.3.2(49): @code{Ada.Characters.Handling}
4603 If an implementation provides a localized definition of @code{Character}
4604 or @code{Wide_Character}, then the effects of the subprograms in
4605 @code{Characters.Handling} should reflect the localizations. See also
4608 Followed. GNAT provides no such localized definitions.
4610 @cindex Bounded-length strings
4611 @item A.4.4(106): Bounded-Length String Handling
4614 Bounded string objects should not be implemented by implicit pointers
4615 and dynamic allocation.
4617 Followed. No implicit pointers or dynamic allocation are used.
4619 @cindex Random number generation
4620 @item A.5.2(46-47): Random Number Generation
4623 Any storage associated with an object of type @code{Generator} should be
4624 reclaimed on exit from the scope of the object.
4630 If the generator period is sufficiently long in relation to the number
4631 of distinct initiator values, then each possible value of
4632 @code{Initiator} passed to @code{Reset} should initiate a sequence of
4633 random numbers that does not, in a practical sense, overlap the sequence
4634 initiated by any other value. If this is not possible, then the mapping
4635 between initiator values and generator states should be a rapidly
4636 varying function of the initiator value.
4638 Followed. The generator period is sufficiently long for the first
4639 condition here to hold true.
4641 @findex Get_Immediate
4642 @item A.10.7(23): @code{Get_Immediate}
4645 The @code{Get_Immediate} procedures should be implemented with
4646 unbuffered input. For a device such as a keyboard, input should be
4647 @dfn{available} if a key has already been typed, whereas for a disk
4648 file, input should always be available except at end of file. For a file
4649 associated with a keyboard-like device, any line-editing features of the
4650 underlying operating system should be disabled during the execution of
4651 @code{Get_Immediate}.
4656 @item B.1(39-41): Pragma @code{Export}
4659 If an implementation supports pragma @code{Export} to a given language,
4660 then it should also allow the main subprogram to be written in that
4661 language. It should support some mechanism for invoking the elaboration
4662 of the Ada library units included in the system, and for invoking the
4663 finalization of the environment task. On typical systems, the
4664 recommended mechanism is to provide two subprograms whose link names are
4665 @code{adainit} and @code{adafinal}. @code{adainit} should contain the
4666 elaboration code for library units. @code{adafinal} should contain the
4667 finalization code. These subprograms should have no effect the second
4668 and subsequent time they are called.
4674 Automatic elaboration of pre-elaborated packages should be
4675 provided when pragma @code{Export} is supported.
4677 Followed when the main program is in Ada. If the main program is in a
4678 foreign language, then
4679 @code{adainit} must be called to elaborate pre-elaborated
4684 For each supported convention @var{L} other than @code{Intrinsic}, an
4685 implementation should support @code{Import} and @code{Export} pragmas
4686 for objects of @var{L}-compatible types and for subprograms, and pragma
4687 @code{Convention} for @var{L}-eligible types and for subprograms,
4688 presuming the other language has corresponding features. Pragma
4689 @code{Convention} need not be supported for scalar types.
4693 @cindex Package @code{Interfaces}
4695 @item B.2(12-13): Package @code{Interfaces}
4698 For each implementation-defined convention identifier, there should be a
4699 child package of package Interfaces with the corresponding name. This
4700 package should contain any declarations that would be useful for
4701 interfacing to the language (implementation) represented by the
4702 convention. Any declarations useful for interfacing to any language on
4703 the given hardware architecture should be provided directly in
4706 Followed. An additional package not defined
4707 in the Ada 95 Reference Manual is @code{Interfaces.CPP}, used
4708 for interfacing to C++.
4712 An implementation supporting an interface to C, COBOL, or Fortran should
4713 provide the corresponding package or packages described in the following
4716 Followed. GNAT provides all the packages described in this section.
4718 @cindex C, interfacing with
4719 @item B.3(63-71): Interfacing with C
4722 An implementation should support the following interface correspondences
4729 An Ada procedure corresponds to a void-returning C function.
4735 An Ada function corresponds to a non-void C function.
4741 An Ada @code{in} scalar parameter is passed as a scalar argument to a C
4748 An Ada @code{in} parameter of an access-to-object type with designated
4749 type @var{T} is passed as a @code{@var{t}*} argument to a C function,
4750 where @var{t} is the C type corresponding to the Ada type @var{T}.
4756 An Ada access @var{T} parameter, or an Ada @code{out} or @code{in out}
4757 parameter of an elementary type @var{T}, is passed as a @code{@var{t}*}
4758 argument to a C function, where @var{t} is the C type corresponding to
4759 the Ada type @var{T}. In the case of an elementary @code{out} or
4760 @code{in out} parameter, a pointer to a temporary copy is used to
4761 preserve by-copy semantics.
4767 An Ada parameter of a record type @var{T}, of any mode, is passed as a
4768 @code{@var{t}*} argument to a C function, where @var{t} is the C
4769 structure corresponding to the Ada type @var{T}.
4771 Followed. This convention may be overridden by the use of the C_Pass_By_Copy
4772 pragma, or Convention, or by explicitly specifying the mechanism for a given
4773 call using an extended import or export pragma.
4777 An Ada parameter of an array type with component type @var{T}, of any
4778 mode, is passed as a @code{@var{t}*} argument to a C function, where
4779 @var{t} is the C type corresponding to the Ada type @var{T}.
4785 An Ada parameter of an access-to-subprogram type is passed as a pointer
4786 to a C function whose prototype corresponds to the designated
4787 subprogram's specification.
4791 @cindex COBOL, interfacing with
4792 @item B.4(95-98): Interfacing with COBOL
4795 An Ada implementation should support the following interface
4796 correspondences between Ada and COBOL@.
4802 An Ada access @var{T} parameter is passed as a @samp{BY REFERENCE} data item of
4803 the COBOL type corresponding to @var{T}.
4809 An Ada in scalar parameter is passed as a @samp{BY CONTENT} data item of
4810 the corresponding COBOL type.
4816 Any other Ada parameter is passed as a @samp{BY REFERENCE} data item of the
4817 COBOL type corresponding to the Ada parameter type; for scalars, a local
4818 copy is used if necessary to ensure by-copy semantics.
4822 @cindex Fortran, interfacing with
4823 @item B.5(22-26): Interfacing with Fortran
4826 An Ada implementation should support the following interface
4827 correspondences between Ada and Fortran:
4833 An Ada procedure corresponds to a Fortran subroutine.
4839 An Ada function corresponds to a Fortran function.
4845 An Ada parameter of an elementary, array, or record type @var{T} is
4846 passed as a @var{T} argument to a Fortran procedure, where @var{T} is
4847 the Fortran type corresponding to the Ada type @var{T}, and where the
4848 INTENT attribute of the corresponding dummy argument matches the Ada
4849 formal parameter mode; the Fortran implementation's parameter passing
4850 conventions are used. For elementary types, a local copy is used if
4851 necessary to ensure by-copy semantics.
4857 An Ada parameter of an access-to-subprogram type is passed as a
4858 reference to a Fortran procedure whose interface corresponds to the
4859 designated subprogram's specification.
4863 @cindex Machine operations
4864 @item C.1(3-5): Access to Machine Operations
4867 The machine code or intrinsic support should allow access to all
4868 operations normally available to assembly language programmers for the
4869 target environment, including privileged instructions, if any.
4875 The interfacing pragmas (see Annex B) should support interface to
4876 assembler; the default assembler should be associated with the
4877 convention identifier @code{Assembler}.
4883 If an entity is exported to assembly language, then the implementation
4884 should allocate it at an addressable location, and should ensure that it
4885 is retained by the linking process, even if not otherwise referenced
4886 from the Ada code. The implementation should assume that any call to a
4887 machine code or assembler subprogram is allowed to read or update every
4888 object that is specified as exported.
4892 @item C.1(10-16): Access to Machine Operations
4895 The implementation should ensure that little or no overhead is
4896 associated with calling intrinsic and machine-code subprograms.
4898 Followed for both intrinsics and machine-code subprograms.
4902 It is recommended that intrinsic subprograms be provided for convenient
4903 access to any machine operations that provide special capabilities or
4904 efficiency and that are not otherwise available through the language
4907 Followed. A full set of machine operation intrinsic subprograms is provided.
4911 Atomic read-modify-write operations---e.g.@:, test and set, compare and
4912 swap, decrement and test, enqueue/dequeue.
4914 Followed on any target supporting such operations.
4918 Standard numeric functions---e.g.@:, sin, log.
4920 Followed on any target supporting such operations.
4924 String manipulation operations---e.g.@:, translate and test.
4926 Followed on any target supporting such operations.
4930 Vector operations---e.g.@:, compare vector against thresholds.
4932 Followed on any target supporting such operations.
4936 Direct operations on I/O ports.
4938 Followed on any target supporting such operations.
4940 @cindex Interrupt support
4941 @item C.3(28): Interrupt Support
4944 If the @code{Ceiling_Locking} policy is not in effect, the
4945 implementation should provide means for the application to specify which
4946 interrupts are to be blocked during protected actions, if the underlying
4947 system allows for a finer-grain control of interrupt blocking.
4949 Followed. The underlying system does not allow for finer-grain control
4950 of interrupt blocking.
4952 @cindex Protected procedure handlers
4953 @item C.3.1(20-21): Protected Procedure Handlers
4956 Whenever possible, the implementation should allow interrupt handlers to
4957 be called directly by the hardware.
4961 This is never possible under IRIX, so this is followed by default.
4963 Followed on any target where the underlying operating system permits
4968 Whenever practical, violations of any
4969 implementation-defined restrictions should be detected before run time.
4971 Followed. Compile time warnings are given when possible.
4973 @cindex Package @code{Interrupts}
4975 @item C.3.2(25): Package @code{Interrupts}
4979 If implementation-defined forms of interrupt handler procedures are
4980 supported, such as protected procedures with parameters, then for each
4981 such form of a handler, a type analogous to @code{Parameterless_Handler}
4982 should be specified in a child package of @code{Interrupts}, with the
4983 same operations as in the predefined package Interrupts.
4987 @cindex Pre-elaboration requirements
4988 @item C.4(14): Pre-elaboration Requirements
4991 It is recommended that pre-elaborated packages be implemented in such a
4992 way that there should be little or no code executed at run time for the
4993 elaboration of entities not already covered by the Implementation
4996 Followed. Executable code is generated in some cases, e.g.@: loops
4997 to initialize large arrays.
4999 @item C.5(8): Pragma @code{Discard_Names}
5003 If the pragma applies to an entity, then the implementation should
5004 reduce the amount of storage used for storing names associated with that
5009 @cindex Package @code{Task_Attributes}
5010 @findex Task_Attributes
5011 @item C.7.2(30): The Package Task_Attributes
5014 Some implementations are targeted to domains in which memory use at run
5015 time must be completely deterministic. For such implementations, it is
5016 recommended that the storage for task attributes will be pre-allocated
5017 statically and not from the heap. This can be accomplished by either
5018 placing restrictions on the number and the size of the task's
5019 attributes, or by using the pre-allocated storage for the first @var{N}
5020 attribute objects, and the heap for the others. In the latter case,
5021 @var{N} should be documented.
5023 Not followed. This implementation is not targeted to such a domain.
5025 @cindex Locking Policies
5026 @item D.3(17): Locking Policies
5030 The implementation should use names that end with @samp{_Locking} for
5031 locking policies defined by the implementation.
5033 Followed. A single implementation-defined locking policy is defined,
5034 whose name (@code{Inheritance_Locking}) follows this suggestion.
5036 @cindex Entry queuing policies
5037 @item D.4(16): Entry Queuing Policies
5040 Names that end with @samp{_Queuing} should be used
5041 for all implementation-defined queuing policies.
5043 Followed. No such implementation-defined queueing policies exist.
5045 @cindex Preemptive abort
5046 @item D.6(9-10): Preemptive Abort
5049 Even though the @code{abort_statement} is included in the list of
5050 potentially blocking operations (see 9.5.1), it is recommended that this
5051 statement be implemented in a way that never requires the task executing
5052 the @code{abort_statement} to block.
5058 On a multi-processor, the delay associated with aborting a task on
5059 another processor should be bounded; the implementation should use
5060 periodic polling, if necessary, to achieve this.
5064 @cindex Tasking restrictions
5065 @item D.7(21): Tasking Restrictions
5068 When feasible, the implementation should take advantage of the specified
5069 restrictions to produce a more efficient implementation.
5071 GNAT currently takes advantage of these restrictions by providing an optimized
5072 run time when the Ravenscar profile and the GNAT restricted run time set
5073 of restrictions are specified. See pragma @code{Ravenscar} and pragma
5074 @code{Restricted_Run_Time} for more details.
5076 @cindex Time, monotonic
5077 @item D.8(47-49): Monotonic Time
5080 When appropriate, implementations should provide configuration
5081 mechanisms to change the value of @code{Tick}.
5083 Such configuration mechanisms are not appropriate to this implementation
5084 and are thus not supported.
5088 It is recommended that @code{Calendar.Clock} and @code{Real_Time.Clock}
5089 be implemented as transformations of the same time base.
5095 It is recommended that the @dfn{best} time base which exists in
5096 the underlying system be available to the application through
5097 @code{Clock}. @dfn{Best} may mean highest accuracy or largest range.
5101 @cindex Partition communication subsystem
5103 @item E.5(28-29): Partition Communication Subsystem
5106 Whenever possible, the PCS on the called partition should allow for
5107 multiple tasks to call the RPC-receiver with different messages and
5108 should allow them to block until the corresponding subprogram body
5111 Followed by GLADE, a separately supplied PCS that can be used with
5116 The @code{Write} operation on a stream of type @code{Params_Stream_Type}
5117 should raise @code{Storage_Error} if it runs out of space trying to
5118 write the @code{Item} into the stream.
5120 Followed by GLADE, a separately supplied PCS that can be used with
5123 @cindex COBOL support
5124 @item F(7): COBOL Support
5127 If COBOL (respectively, C) is widely supported in the target
5128 environment, implementations supporting the Information Systems Annex
5129 should provide the child package @code{Interfaces.COBOL} (respectively,
5130 @code{Interfaces.C}) specified in Annex B and should support a
5131 @code{convention_identifier} of COBOL (respectively, C) in the interfacing
5132 pragmas (see Annex B), thus allowing Ada programs to interface with
5133 programs written in that language.
5137 @cindex Decimal radix support
5138 @item F.1(2): Decimal Radix Support
5141 Packed decimal should be used as the internal representation for objects
5142 of subtype @var{S} when @var{S}'Machine_Radix = 10.
5144 Not followed. GNAT ignores @var{S}'Machine_Radix and always uses binary
5151 If Fortran (respectively, C) is widely supported in the target
5152 environment, implementations supporting the Numerics Annex
5153 should provide the child package @code{Interfaces.Fortran} (respectively,
5154 @code{Interfaces.C}) specified in Annex B and should support a
5155 @code{convention_identifier} of Fortran (respectively, C) in the interfacing
5156 pragmas (see Annex B), thus allowing Ada programs to interface with
5157 programs written in that language.
5161 @cindex Complex types
5162 @item G.1.1(56-58): Complex Types
5165 Because the usual mathematical meaning of multiplication of a complex
5166 operand and a real operand is that of the scaling of both components of
5167 the former by the latter, an implementation should not perform this
5168 operation by first promoting the real operand to complex type and then
5169 performing a full complex multiplication. In systems that, in the
5170 future, support an Ada binding to IEC 559:1989, the latter technique
5171 will not generate the required result when one of the components of the
5172 complex operand is infinite. (Explicit multiplication of the infinite
5173 component by the zero component obtained during promotion yields a NaN
5174 that propagates into the final result.) Analogous advice applies in the
5175 case of multiplication of a complex operand and a pure-imaginary
5176 operand, and in the case of division of a complex operand by a real or
5177 pure-imaginary operand.
5183 Similarly, because the usual mathematical meaning of addition of a
5184 complex operand and a real operand is that the imaginary operand remains
5185 unchanged, an implementation should not perform this operation by first
5186 promoting the real operand to complex type and then performing a full
5187 complex addition. In implementations in which the @code{Signed_Zeros}
5188 attribute of the component type is @code{True} (and which therefore
5189 conform to IEC 559:1989 in regard to the handling of the sign of zero in
5190 predefined arithmetic operations), the latter technique will not
5191 generate the required result when the imaginary component of the complex
5192 operand is a negatively signed zero. (Explicit addition of the negative
5193 zero to the zero obtained during promotion yields a positive zero.)
5194 Analogous advice applies in the case of addition of a complex operand
5195 and a pure-imaginary operand, and in the case of subtraction of a
5196 complex operand and a real or pure-imaginary operand.
5202 Implementations in which @code{Real'Signed_Zeros} is @code{True} should
5203 attempt to provide a rational treatment of the signs of zero results and
5204 result components. As one example, the result of the @code{Argument}
5205 function should have the sign of the imaginary component of the
5206 parameter @code{X} when the point represented by that parameter lies on
5207 the positive real axis; as another, the sign of the imaginary component
5208 of the @code{Compose_From_Polar} function should be the same as
5209 (respectively, the opposite of) that of the @code{Argument} parameter when that
5210 parameter has a value of zero and the @code{Modulus} parameter has a
5211 nonnegative (respectively, negative) value.
5215 @cindex Complex elementary functions
5216 @item G.1.2(49): Complex Elementary Functions
5219 Implementations in which @code{Complex_Types.Real'Signed_Zeros} is
5220 @code{True} should attempt to provide a rational treatment of the signs
5221 of zero results and result components. For example, many of the complex
5222 elementary functions have components that are odd functions of one of
5223 the parameter components; in these cases, the result component should
5224 have the sign of the parameter component at the origin. Other complex
5225 elementary functions have zero components whose sign is opposite that of
5226 a parameter component at the origin, or is always positive or always
5231 @cindex Accuracy requirements
5232 @item G.2.4(19): Accuracy Requirements
5235 The versions of the forward trigonometric functions without a
5236 @code{Cycle} parameter should not be implemented by calling the
5237 corresponding version with a @code{Cycle} parameter of
5238 @code{2.0*Numerics.Pi}, since this will not provide the required
5239 accuracy in some portions of the domain. For the same reason, the
5240 version of @code{Log} without a @code{Base} parameter should not be
5241 implemented by calling the corresponding version with a @code{Base}
5242 parameter of @code{Numerics.e}.
5246 @cindex Complex arithmetic accuracy
5247 @cindex Accuracy, complex arithmetic
5248 @item G.2.6(15): Complex Arithmetic Accuracy
5252 The version of the @code{Compose_From_Polar} function without a
5253 @code{Cycle} parameter should not be implemented by calling the
5254 corresponding version with a @code{Cycle} parameter of
5255 @code{2.0*Numerics.Pi}, since this will not provide the required
5256 accuracy in some portions of the domain.
5261 @node Implementation Defined Characteristics
5262 @chapter Implementation Defined Characteristics
5263 In addition to the implementation dependent pragmas and attributes, and
5264 the implementation advice, there are a number of other features of Ada
5265 95 that are potentially implementation dependent. These are mentioned
5266 throughout the Ada 95 Reference Manual, and are summarized in annex M@.
5268 A requirement for conforming Ada compilers is that they provide
5269 documentation describing how the implementation deals with each of these
5270 issues. In this chapter, you will find each point in annex M listed
5271 followed by a description in italic font of how GNAT
5275 implementation on IRIX 5.3 operating system or greater
5277 handles the implementation dependence.
5279 You can use this chapter as a guide to minimizing implementation
5280 dependent features in your programs if portability to other compilers
5281 and other operating systems is an important consideration. The numbers
5282 in each section below correspond to the paragraph number in the Ada 95
5288 @strong{2}. Whether or not each recommendation given in Implementation
5289 Advice is followed. See 1.1.2(37).
5292 @xref{Implementation Advice}.
5297 @strong{3}. Capacity limitations of the implementation. See 1.1.3(3).
5300 The complexity of programs that can be processed is limited only by the
5301 total amount of available virtual memory, and disk space for the
5302 generated object files.
5307 @strong{4}. Variations from the standard that are impractical to avoid
5308 given the implementation's execution environment. See 1.1.3(6).
5311 There are no variations from the standard.
5316 @strong{5}. Which @code{code_statement}s cause external
5317 interactions. See 1.1.3(10).
5320 Any @code{code_statement} can potentially cause external interactions.
5325 @strong{6}. The coded representation for the text of an Ada
5326 program. See 2.1(4).
5329 See separate section on source representation.
5334 @strong{7}. The control functions allowed in comments. See 2.1(14).
5337 See separate section on source representation.
5342 @strong{8}. The representation for an end of line. See 2.2(2).
5345 See separate section on source representation.
5350 @strong{9}. Maximum supported line length and lexical element
5351 length. See 2.2(15).
5354 The maximum line length is 255 characters an the maximum length of a
5355 lexical element is also 255 characters.
5360 @strong{10}. Implementation defined pragmas. See 2.8(14).
5364 @xref{Implementation Defined Pragmas}.
5369 @strong{11}. Effect of pragma @code{Optimize}. See 2.8(27).
5372 Pragma @code{Optimize}, if given with a @code{Time} or @code{Space}
5373 parameter, checks that the optimization flag is set, and aborts if it is
5379 @strong{12}. The sequence of characters of the value returned by
5380 @code{@var{S}'Image} when some of the graphic characters of
5381 @code{@var{S}'Wide_Image} are not defined in @code{Character}. See
5385 The sequence of characters is as defined by the wide character encoding
5386 method used for the source. See section on source representation for
5392 @strong{13}. The predefined integer types declared in
5393 @code{Standard}. See 3.5.4(25).
5397 @item Short_Short_Integer
5400 (Short) 16 bit signed
5404 64 bit signed (Alpha OpenVMS only)
5405 32 bit signed (all other targets)
5406 @item Long_Long_Integer
5413 @strong{14}. Any nonstandard integer types and the operators defined
5414 for them. See 3.5.4(26).
5417 There are no nonstandard integer types.
5422 @strong{15}. Any nonstandard real types and the operators defined for
5426 There are no nonstandard real types.
5431 @strong{16}. What combinations of requested decimal precision and range
5432 are supported for floating point types. See 3.5.7(7).
5435 The precision and range is as defined by the IEEE standard.
5440 @strong{17}. The predefined floating point types declared in
5441 @code{Standard}. See 3.5.7(16).
5448 (Short) 32 bit IEEE short
5451 @item Long_Long_Float
5452 64 bit IEEE long (80 bit IEEE long on x86 processors)
5458 @strong{18}. The small of an ordinary fixed point type. See 3.5.9(8).
5461 @code{Fine_Delta} is 2**(@minus{}63)
5466 @strong{19}. What combinations of small, range, and digits are
5467 supported for fixed point types. See 3.5.9(10).
5470 Any combinations are permitted that do not result in a small less than
5471 @code{Fine_Delta} and do not result in a mantissa larger than 63 bits.
5472 If the mantissa is larger than 53 bits on machines where Long_Long_Float
5473 is 64 bits (true of all architectures except ia32), then the output from
5474 Text_IO is accurate to only 53 bits, rather than the full mantissa. This
5475 is because floating-point conversions are used to convert fixed point.
5480 @strong{20}. The result of @code{Tags.Expanded_Name} for types declared
5481 within an unnamed @code{block_statement}. See 3.9(10).
5484 Block numbers of the form @code{B@var{nnn}}, where @var{nnn} is a
5485 decimal integer are allocated.
5490 @strong{21}. Implementation-defined attributes. See 4.1.4(12).
5493 @xref{Implementation Defined Attributes}.
5498 @strong{22}. Any implementation-defined time types. See 9.6(6).
5501 There are no implementation-defined time types.
5506 @strong{23}. The time base associated with relative delays.
5509 See 9.6(20). The time base used is that provided by the C library
5510 function @code{gettimeofday}.
5515 @strong{24}. The time base of the type @code{Calendar.Time}. See
5519 The time base used is that provided by the C library function
5520 @code{gettimeofday}.
5525 @strong{25}. The time zone used for package @code{Calendar}
5526 operations. See 9.6(24).
5529 The time zone used by package @code{Calendar} is the current system time zone
5530 setting for local time, as accessed by the C library function
5536 @strong{26}. Any limit on @code{delay_until_statements} of
5537 @code{select_statements}. See 9.6(29).
5540 There are no such limits.
5545 @strong{27}. Whether or not two non overlapping parts of a composite
5546 object are independently addressable, in the case where packing, record
5547 layout, or @code{Component_Size} is specified for the object. See
5551 Separate components are independently addressable if they do not share
5552 overlapping storage units.
5557 @strong{28}. The representation for a compilation. See 10.1(2).
5560 A compilation is represented by a sequence of files presented to the
5561 compiler in a single invocation of the @code{gcc} command.
5566 @strong{29}. Any restrictions on compilations that contain multiple
5567 compilation_units. See 10.1(4).
5570 No single file can contain more than one compilation unit, but any
5571 sequence of files can be presented to the compiler as a single
5577 @strong{30}. The mechanisms for creating an environment and for adding
5578 and replacing compilation units. See 10.1.4(3).
5581 See separate section on compilation model.
5586 @strong{31}. The manner of explicitly assigning library units to a
5587 partition. See 10.2(2).
5590 If a unit contains an Ada main program, then the Ada units for the partition
5591 are determined by recursive application of the rules in the Ada Reference
5592 Manual section 10.2(2-6). In other words, the Ada units will be those that
5593 are needed by the main program, and then this definition of need is applied
5594 recursively to those units, and the partition contains the transitive
5595 closure determined by this relationship. In short, all the necessary units
5596 are included, with no need to explicitly specify the list. If additional
5597 units are required, e.g.@: by foreign language units, then all units must be
5598 mentioned in the context clause of one of the needed Ada units.
5600 If the partition contains no main program, or if the main program is in
5601 a language other than Ada, then GNAT
5602 provides the binder options @code{-z} and @code{-n} respectively, and in this case a
5603 list of units can be explicitly supplied to the binder for inclusion in
5604 the partition (all units needed by these units will also be included
5605 automatically). For full details on the use of these options, refer to
5606 the @cite{GNAT User's Guide} sections on Binding and Linking.
5611 @strong{32}. The implementation-defined means, if any, of specifying
5612 which compilation units are needed by a given compilation unit. See
5616 The units needed by a given compilation unit are as defined in
5617 the Ada Reference Manual section 10.2(2-6). There are no
5618 implementation-defined pragmas or other implementation-defined
5619 means for specifying needed units.
5624 @strong{33}. The manner of designating the main subprogram of a
5625 partition. See 10.2(7).
5628 The main program is designated by providing the name of the
5629 corresponding @file{ALI} file as the input parameter to the binder.
5634 @strong{34}. The order of elaboration of @code{library_items}. See
5638 The first constraint on ordering is that it meets the requirements of
5639 chapter 10 of the Ada 95 Reference Manual. This still leaves some
5640 implementation dependent choices, which are resolved by first
5641 elaborating bodies as early as possible (i.e.@: in preference to specs
5642 where there is a choice), and second by evaluating the immediate with
5643 clauses of a unit to determine the probably best choice, and
5644 third by elaborating in alphabetical order of unit names
5645 where a choice still remains.
5650 @strong{35}. Parameter passing and function return for the main
5651 subprogram. See 10.2(21).
5654 The main program has no parameters. It may be a procedure, or a function
5655 returning an integer type. In the latter case, the returned integer
5656 value is the return code of the program.
5661 @strong{36}. The mechanisms for building and running partitions. See
5665 GNAT itself supports programs with only a single partition. The GNATDIST
5666 tool provided with the GLADE package (which also includes an implementation
5667 of the PCS) provides a completely flexible method for building and running
5668 programs consisting of multiple partitions. See the separate GLADE manual
5674 @strong{37}. The details of program execution, including program
5675 termination. See 10.2(25).
5678 See separate section on compilation model.
5683 @strong{38}. The semantics of any non-active partitions supported by the
5684 implementation. See 10.2(28).
5687 Passive partitions are supported on targets where shared memory is
5688 provided by the operating system. See the GLADE reference manual for
5694 @strong{39}. The information returned by @code{Exception_Message}. See
5698 Exception message returns the null string unless a specific message has
5699 been passed by the program.
5704 @strong{40}. The result of @code{Exceptions.Exception_Name} for types
5705 declared within an unnamed @code{block_statement}. See 11.4.1(12).
5708 Blocks have implementation defined names of the form @code{B@var{nnn}}
5709 where @var{nnn} is an integer.
5714 @strong{41}. The information returned by
5715 @code{Exception_Information}. See 11.4.1(13).
5718 @code{Exception_Information} returns a string in the following format:
5721 @emph{Exception_Name:} nnnnn
5722 @emph{Message:} mmmmm
5724 @emph{Call stack traceback locations:}
5725 0xhhhh 0xhhhh 0xhhhh ... 0xhhh
5733 @code{nnnn} is the fully qualified name of the exception in all upper
5734 case letters. This line is always present.
5737 @code{mmmm} is the message (this line present only if message is non-null)
5740 @code{ppp} is the Process Id value as a decimal integer (this line is
5741 present only if the Process Id is non-zero). Currently we are
5742 not making use of this field.
5745 The Call stack traceback locations line and the following values
5746 are present only if at least one traceback location was recorded.
5747 The values are given in C style format, with lower case letters
5748 for a-f, and only as many digits present as are necessary.
5752 The line terminator sequence at the end of each line, including
5753 the last line is a single @code{LF} character (@code{16#0A#}).
5758 @strong{42}. Implementation-defined check names. See 11.5(27).
5761 No implementation-defined check names are supported.
5766 @strong{43}. The interpretation of each aspect of representation. See
5770 See separate section on data representations.
5775 @strong{44}. Any restrictions placed upon representation items. See
5779 See separate section on data representations.
5784 @strong{45}. The meaning of @code{Size} for indefinite subtypes. See
5788 Size for an indefinite subtype is the maximum possible size, except that
5789 for the case of a subprogram parameter, the size of the parameter object
5795 @strong{46}. The default external representation for a type tag. See
5799 The default external representation for a type tag is the fully expanded
5800 name of the type in upper case letters.
5805 @strong{47}. What determines whether a compilation unit is the same in
5806 two different partitions. See 13.3(76).
5809 A compilation unit is the same in two different partitions if and only
5810 if it derives from the same source file.
5815 @strong{48}. Implementation-defined components. See 13.5.1(15).
5818 The only implementation defined component is the tag for a tagged type,
5819 which contains a pointer to the dispatching table.
5824 @strong{49}. If @code{Word_Size} = @code{Storage_Unit}, the default bit
5825 ordering. See 13.5.3(5).
5828 @code{Word_Size} (32) is not the same as @code{Storage_Unit} (8) for this
5829 implementation, so no non-default bit ordering is supported. The default
5830 bit ordering corresponds to the natural endianness of the target architecture.
5835 @strong{50}. The contents of the visible part of package @code{System}
5836 and its language-defined children. See 13.7(2).
5839 See the definition of these packages in files @file{system.ads} and
5840 @file{s-stoele.ads}.
5845 @strong{51}. The contents of the visible part of package
5846 @code{System.Machine_Code}, and the meaning of
5847 @code{code_statements}. See 13.8(7).
5850 See the definition and documentation in file @file{s-maccod.ads}.
5855 @strong{52}. The effect of unchecked conversion. See 13.9(11).
5858 Unchecked conversion between types of the same size
5859 and results in an uninterpreted transmission of the bits from one type
5860 to the other. If the types are of unequal sizes, then in the case of
5861 discrete types, a shorter source is first zero or sign extended as
5862 necessary, and a shorter target is simply truncated on the left.
5863 For all non-discrete types, the source is first copied if necessary
5864 to ensure that the alignment requirements of the target are met, then
5865 a pointer is constructed to the source value, and the result is obtained
5866 by dereferencing this pointer after converting it to be a pointer to the
5872 @strong{53}. The manner of choosing a storage pool for an access type
5873 when @code{Storage_Pool} is not specified for the type. See 13.11(17).
5876 There are 3 different standard pools used by the compiler when
5877 @code{Storage_Pool} is not specified depending whether the type is local
5878 to a subprogram or defined at the library level and whether
5879 @code{Storage_Size}is specified or not. See documentation in the runtime
5880 library units @code{System.Pool_Global}, @code{System.Pool_Size} and
5881 @code{System.Pool_Local} in files @file{s-poosiz.ads},
5882 @file{s-pooglo.ads} and @file{s-pooloc.ads} for full details on the
5888 @strong{54}. Whether or not the implementation provides user-accessible
5889 names for the standard pool type(s). See 13.11(17).
5893 See documentation in the sources of the run time mentioned in paragraph
5894 @strong{53} . All these pools are accessible by means of @code{with}'ing
5900 @strong{55}. The meaning of @code{Storage_Size}. See 13.11(18).
5903 @code{Storage_Size} is measured in storage units, and refers to the
5904 total space available for an access type collection, or to the primary
5905 stack space for a task.
5910 @strong{56}. Implementation-defined aspects of storage pools. See
5914 See documentation in the sources of the run time mentioned in paragraph
5915 @strong{53} for details on GNAT-defined aspects of storage pools.
5920 @strong{57}. The set of restrictions allowed in a pragma
5921 @code{Restrictions}. See 13.12(7).
5924 All RM defined Restriction identifiers are implemented. The following
5925 additional restriction identifiers are provided. There are two separate
5926 lists of implementation dependent restriction identifiers. The first
5927 set requires consistency throughout a partition (in other words, if the
5928 restriction identifier is used for any compilation unit in the partition,
5929 then all compilation units in the partition must obey the restriction.
5933 @item Boolean_Entry_Barriers
5934 @findex Boolean_Entry_Barriers
5935 This restriction ensures at compile time that barriers in entry declarations
5936 for protected types are restricted to references to simple boolean variables
5937 defined in the private part of the protected type. No other form of entry
5938 barriers is permitted. This is one of the restrictions of the Ravenscar
5939 profile for limited tasking (see also pragma @code{Ravenscar}).
5941 @item Max_Entry_Queue_Depth => Expr
5942 @findex Max_Entry_Queue_Depth
5943 This restriction is a declaration that any protected entry compiled in
5944 the scope of the restriction has at most the specified number of
5945 tasks waiting on the entry
5946 at any one time, and so no queue is required. This restriction is not
5947 checked at compile time. A program execution is erroneous if an attempt
5948 is made to queue more than the specified number of tasks on such an entry.
5952 This restriction ensures at compile time that there is no implicit or
5953 explicit dependence on the package @code{Ada.Calendar}.
5955 @item No_Dynamic_Interrupts
5956 @findex No_Dynamic_Interrupts
5957 This restriction ensures at compile time that there is no attempt to
5958 dynamically associate interrupts. Only static association is allowed.
5960 @item No_Enumeration_Maps
5961 @findex No_Enumeration_Maps
5962 This restriction ensures at compile time that no operations requiring
5963 enumeration maps are used (that is Image and Value attributes applied
5964 to enumeration types).
5966 @item No_Entry_Calls_In_Elaboration_Code
5967 @findex No_Entry_Calls_In_Elaboration_Code
5968 This restriction ensures at compile time that no task or protected entry
5969 calls are made during elaboration code. As a result of the use of this
5970 restriction, the compiler can assume that no code past an accept statement
5971 in a task can be executed at elaboration time.
5973 @item No_Exception_Handlers
5974 @findex No_Exception_Handlers
5975 This restriction ensures at compile time that there are no explicit
5978 @item No_Implicit_Conditionals
5979 @findex No_Implicit_Conditionals
5980 This restriction ensures that the generated code does not contain any
5981 implicit conditionals, either by modifying the generated code where possible,
5982 or by rejecting any construct that would otherwise generate an implicit
5983 conditional. The details and use of this restriction are described in
5984 more detail in the High Integrity product documentation.
5986 @item No_Implicit_Loops
5987 @findex No_Implicit_Loops
5988 This restriction ensures that the generated code does not contain any
5989 implicit @code{for} loops, either by modifying
5990 the generated code where possible,
5991 or by rejecting any construct that would otherwise generate an implicit
5992 @code{for} loop. The details and use of this restriction are described in
5993 more detail in the High Integrity product documentation.
5995 @item No_Local_Protected_Objects
5996 @findex No_Local_Protected_Objects
5997 This restriction ensures at compile time that protected objects are
5998 only declared at the library level.
6000 @item No_Protected_Type_Allocators
6001 @findex No_Protected_Type_Allocators
6002 This restriction ensures at compile time that there are no allocator
6003 expressions that attempt to allocate protected objects.
6005 @item No_Secondary_Stack
6006 @findex No_Secondary_Stack
6007 This restriction ensures at compile time that the generated code does not
6008 contain any reference to the secondary stack. The secondary stack is used
6009 to implement functions returning unconstrained objects (arrays or records)
6011 The details and use of this restriction are described in
6012 more detail in the High Integrity product documentation.
6014 @item No_Select_Statements
6015 @findex No_Select_Statements
6016 This restriction ensures at compile time no select statements of any kind
6017 are permitted, that is the keyword @code{select} may not appear.
6018 This is one of the restrictions of the Ravenscar
6019 profile for limited tasking (see also pragma @code{Ravenscar}).
6021 @item No_Standard_Storage_Pools
6022 @findex No_Standard_Storage_Pools
6023 This restriction ensures at compile time that no access types
6024 use the standard default storage pool. Any access type declared must
6025 have an explicit Storage_Pool attribute defined specifying a
6026 user-defined storage pool.
6030 This restriction ensures at compile time that there are no implicit or
6031 explicit dependencies on the package @code{Ada.Streams}.
6033 @item No_Task_Attributes
6034 @findex No_Task_Attributes
6035 This restriction ensures at compile time that there are no implicit or
6036 explicit dependencies on the package @code{Ada.Task_Attributes}.
6038 @item No_Task_Termination
6039 @findex No_Task_Termination
6040 This restriction ensures at compile time that no terminate alternatives
6041 appear in any task body.
6045 This restriction prevents the declaration of tasks or task types throughout
6046 the partition. It is similar in effect to the use of @code{Max_Tasks => 0}
6047 except that violations are caught at compile time and cause an error message
6048 to be output either by the compiler or binder.
6050 @item No_Wide_Characters
6051 @findex No_Wide_Characters
6052 This restriction ensures at compile time that no uses of the types
6053 @code{Wide_Character} or @code{Wide_String}
6054 appear, and that no wide character literals
6055 appear in the program (that is literals representing characters not in
6056 type @code{Character}.
6058 @item Static_Priorities
6059 @findex Static_Priorities
6060 This restriction ensures at compile time that all priority expressions
6061 are static, and that there are no dependencies on the package
6062 @code{Ada.Dynamic_Priorities}.
6064 @item Static_Storage_Size
6065 @findex Static_Storage_Size
6066 This restriction ensures at compile time that any expression appearing
6067 in a Storage_Size pragma or attribute definition clause is static.
6072 The second set of implementation dependent restriction identifiers
6073 does not require partition-wide consistency.
6074 The restriction may be enforced for a single
6075 compilation unit without any effect on any of the
6076 other compilation units in the partition.
6080 @item No_Elaboration_Code
6081 @findex No_Elaboration_Code
6082 This restriction ensures at compile time that no elaboration code is
6083 generated. Note that this is not the same condition as is enforced
6084 by pragma @code{Preelaborate}. There are cases in which pragma @code{Preelaborate}
6085 still permits code to be generated (e.g.@: code to initialize a large
6086 array to all zeroes), and there are cases of units which do not meet
6087 the requirements for pragma @code{Preelaborate}, but for which no elaboration
6088 code is generated. Generally, it is the case that preelaborable units
6089 will meet the restrictions, with the exception of large aggregates
6090 initialized with an others_clause, and exception declarations (which
6091 generate calls to a run-time registry procedure). Note that this restriction
6092 is enforced on a unit by unit basis, it need not be obeyed consistently
6093 throughout a partition.
6095 @item No_Entry_Queue
6096 @findex No_Entry_Queue
6097 This restriction is a declaration that any protected entry compiled in
6098 the scope of the restriction has at most one task waiting on the entry
6099 at any one time, and so no queue is required. This restriction is not
6100 checked at compile time. A program execution is erroneous if an attempt
6101 is made to queue a second task on such an entry.
6103 @item No_Implementation_Attributes
6104 @findex No_Implementation_Attributes
6105 This restriction checks at compile time that no GNAT-defined attributes
6106 are present. With this restriction, the only attributes that can be used
6107 are those defined in the Ada 95 Reference Manual.
6109 @item No_Implementation_Pragmas
6110 @findex No_Implementation_Pragmas
6111 This restriction checks at compile time that no GNAT-defined pragmas
6112 are present. With this restriction, the only pragmas that can be used
6113 are those defined in the Ada 95 Reference Manual.
6115 @item No_Implementation_Restrictions
6116 @findex No_Implementation_Restrictions
6117 This restriction checks at compile time that no GNAT-defined restriction
6118 identifiers (other than @code{No_Implementation_Restrictions} itself)
6119 are present. With this restriction, the only other restriction identifiers
6120 that can be used are those defined in the Ada 95 Reference Manual.
6127 @strong{58}. The consequences of violating limitations on
6128 @code{Restrictions} pragmas. See 13.12(9).
6131 Restrictions that can be checked at compile time result in illegalities
6132 if violated. Currently there are no other consequences of violating
6138 @strong{59}. The representation used by the @code{Read} and
6139 @code{Write} attributes of elementary types in terms of stream
6140 elements. See 13.13.2(9).
6143 The representation is the in-memory representation of the base type of
6144 the type, using the number of bits corresponding to the
6145 @code{@var{type}'Size} value, and the natural ordering of the machine.
6150 @strong{60}. The names and characteristics of the numeric subtypes
6151 declared in the visible part of package @code{Standard}. See A.1(3).
6154 See items describing the integer and floating-point types supported.
6159 @strong{61}. The accuracy actually achieved by the elementary
6160 functions. See A.5.1(1).
6163 The elementary functions correspond to the functions available in the C
6164 library. Only fast math mode is implemented.
6169 @strong{62}. The sign of a zero result from some of the operators or
6170 functions in @code{Numerics.Generic_Elementary_Functions}, when
6171 @code{Float_Type'Signed_Zeros} is @code{True}. See A.5.1(46).
6174 The sign of zeroes follows the requirements of the IEEE 754 standard on
6180 @strong{63}. The value of
6181 @code{Numerics.Float_Random.Max_Image_Width}. See A.5.2(27).
6184 Maximum image width is 649, see library file @file{a-numran.ads}.
6189 @strong{64}. The value of
6190 @code{Numerics.Discrete_Random.Max_Image_Width}. See A.5.2(27).
6193 Maximum image width is 80, see library file @file{a-nudira.ads}.
6198 @strong{65}. The algorithms for random number generation. See
6202 The algorithm is documented in the source files @file{a-numran.ads} and
6203 @file{a-numran.adb}.
6208 @strong{66}. The string representation of a random number generator's
6209 state. See A.5.2(38).
6212 See the documentation contained in the file @file{a-numran.adb}.
6217 @strong{67}. The minimum time interval between calls to the
6218 time-dependent Reset procedure that are guaranteed to initiate different
6219 random number sequences. See A.5.2(45).
6222 The minimum period between reset calls to guarantee distinct series of
6223 random numbers is one microsecond.
6228 @strong{68}. The values of the @code{Model_Mantissa},
6229 @code{Model_Emin}, @code{Model_Epsilon}, @code{Model},
6230 @code{Safe_First}, and @code{Safe_Last} attributes, if the Numerics
6231 Annex is not supported. See A.5.3(72).
6234 See the source file @file{ttypef.ads} for the values of all numeric
6240 @strong{69}. Any implementation-defined characteristics of the
6241 input-output packages. See A.7(14).
6244 There are no special implementation defined characteristics for these
6250 @strong{70}. The value of @code{Buffer_Size} in @code{Storage_IO}. See
6254 All type representations are contiguous, and the @code{Buffer_Size} is
6255 the value of @code{@var{type}'Size} rounded up to the next storage unit
6261 @strong{71}. External files for standard input, standard output, and
6262 standard error See A.10(5).
6265 These files are mapped onto the files provided by the C streams
6266 libraries. See source file @file{i-cstrea.ads} for further details.
6271 @strong{72}. The accuracy of the value produced by @code{Put}. See
6275 If more digits are requested in the output than are represented by the
6276 precision of the value, zeroes are output in the corresponding least
6277 significant digit positions.
6282 @strong{73}. The meaning of @code{Argument_Count}, @code{Argument}, and
6283 @code{Command_Name}. See A.15(1).
6286 These are mapped onto the @code{argv} and @code{argc} parameters of the
6287 main program in the natural manner.
6292 @strong{74}. Implementation-defined convention names. See B.1(11).
6295 The following convention names are supported
6303 Synonym for Assembler
6305 Synonym for Assembler
6308 @item C_Pass_By_Copy
6309 Allowed only for record types, like C, but also notes that record
6310 is to be passed by copy rather than reference.
6316 Treated the same as C
6318 Treated the same as C
6322 For support of pragma @code{Import} with convention Intrinsic, see
6323 separate section on Intrinsic Subprograms.
6325 Stdcall (used for Windows implementations only). This convention correspond
6326 to the WINAPI (previously called Pascal convention) C/C++ convention under
6327 Windows. A function with this convention cleans the stack before exit.
6333 Stubbed is a special convention used to indicate that the body of the
6334 subprogram will be entirely ignored. Any call to the subprogram
6335 is converted into a raise of the @code{Program_Error} exception. If a
6336 pragma @code{Import} specifies convention @code{stubbed} then no body need
6337 be present at all. This convention is useful during development for the
6338 inclusion of subprograms whose body has not yet been written.
6342 In addition, all otherwise unrecognized convention names are also
6343 treated as being synonymous with convention C@. In all implementations
6344 except for VMS, use of such other names results in a warning. In VMS
6345 implementations, these names are accepted silently.
6350 @strong{75}. The meaning of link names. See B.1(36).
6353 Link names are the actual names used by the linker.
6358 @strong{76}. The manner of choosing link names when neither the link
6359 name nor the address of an imported or exported entity is specified. See
6363 The default linker name is that which would be assigned by the relevant
6364 external language, interpreting the Ada name as being in all lower case
6370 @strong{77}. The effect of pragma @code{Linker_Options}. See B.1(37).
6373 The string passed to @code{Linker_Options} is presented uninterpreted as
6374 an argument to the link command, unless it contains Ascii.NUL characters.
6375 NUL characters if they appear act as argument separators, so for example
6378 pragma Linker_Options ("-labc" & ASCII.Nul & "-ldef");
6382 causes two separate arguments @code{-labc} and @code{-ldef} to be passed to the
6383 linker. The order of linker options is preserved for a given unit. The final
6384 list of options passed to the linker is in reverse order of the elaboration
6385 order. For example, linker options fo a body always appear before the options
6386 from the corresponding package spec.
6391 @strong{78}. The contents of the visible part of package
6392 @code{Interfaces} and its language-defined descendants. See B.2(1).
6395 See files with prefix @file{i-} in the distributed library.
6400 @strong{79}. Implementation-defined children of package
6401 @code{Interfaces}. The contents of the visible part of package
6402 @code{Interfaces}. See B.2(11).
6405 See files with prefix @file{i-} in the distributed library.
6410 @strong{80}. The types @code{Floating}, @code{Long_Floating},
6411 @code{Binary}, @code{Long_Binary}, @code{Decimal_ Element}, and
6412 @code{COBOL_Character}; and the initialization of the variables
6413 @code{Ada_To_COBOL} and @code{COBOL_To_Ada}, in
6414 @code{Interfaces.COBOL}. See B.4(50).
6421 (Floating) Long_Float
6426 @item Decimal_Element
6428 @item COBOL_Character
6432 For initialization, see the file @file{i-cobol.ads} in the distributed library.
6437 @strong{81}. Support for access to machine instructions. See C.1(1).
6440 See documentation in file @file{s-maccod.ads} in the distributed library.
6445 @strong{82}. Implementation-defined aspects of access to machine
6446 operations. See C.1(9).
6449 See documentation in file @file{s-maccod.ads} in the distributed library.
6454 @strong{83}. Implementation-defined aspects of interrupts. See C.3(2).
6457 Interrupts are mapped to signals or conditions as appropriate. See
6459 @code{Ada.Interrupt_Names} in source file @file{a-intnam.ads} for details
6460 on the interrupts supported on a particular target.
6465 @strong{84}. Implementation-defined aspects of pre-elaboration. See
6469 GNAT does not permit a partition to be restarted without reloading,
6470 except under control of the debugger.
6475 @strong{85}. The semantics of pragma @code{Discard_Names}. See C.5(7).
6478 Pragma @code{Discard_Names} causes names of enumeration literals to
6479 be suppressed. In the presence of this pragma, the Image attribute
6480 provides the image of the Pos of the literal, and Value accepts
6486 @strong{86}. The result of the @code{Task_Identification.Image}
6487 attribute. See C.7.1(7).
6490 The result of this attribute is an 8-digit hexadecimal string
6491 representing the virtual address of the task control block.
6496 @strong{87}. The value of @code{Current_Task} when in a protected entry
6497 or interrupt handler. See C.7.1(17).
6500 Protected entries or interrupt handlers can be executed by any
6501 convenient thread, so the value of @code{Current_Task} is undefined.
6506 @strong{88}. The effect of calling @code{Current_Task} from an entry
6507 body or interrupt handler. See C.7.1(19).
6510 The effect of calling @code{Current_Task} from an entry body or
6511 interrupt handler is to return the identification of the task currently
6517 @strong{89}. Implementation-defined aspects of
6518 @code{Task_Attributes}. See C.7.2(19).
6521 There are no implementation-defined aspects of @code{Task_Attributes}.
6526 @strong{90}. Values of all @code{Metrics}. See D(2).
6529 The metrics information for GNAT depends on the performance of the
6530 underlying operating system. The sources of the run-time for tasking
6531 implementation, together with the output from @code{-gnatG} can be
6532 used to determine the exact sequence of operating systems calls made
6533 to implement various tasking constructs. Together with appropriate
6534 information on the performance of the underlying operating system,
6535 on the exact target in use, this information can be used to determine
6536 the required metrics.
6541 @strong{91}. The declarations of @code{Any_Priority} and
6542 @code{Priority}. See D.1(11).
6545 See declarations in file @file{system.ads}.
6550 @strong{92}. Implementation-defined execution resources. See D.1(15).
6553 There are no implementation-defined execution resources.
6558 @strong{93}. Whether, on a multiprocessor, a task that is waiting for
6559 access to a protected object keeps its processor busy. See D.2.1(3).
6562 On a multi-processor, a task that is waiting for access to a protected
6563 object does not keep its processor busy.
6568 @strong{94}. The affect of implementation defined execution resources
6569 on task dispatching. See D.2.1(9).
6574 Tasks map to IRIX threads, and the dispatching policy is as defined by
6575 the IRIX implementation of threads.
6577 Tasks map to threads in the threads package used by GNAT@. Where possible
6578 and appropriate, these threads correspond to native threads of the
6579 underlying operating system.
6584 @strong{95}. Implementation-defined @code{policy_identifiers} allowed
6585 in a pragma @code{Task_Dispatching_Policy}. See D.2.2(3).
6588 There are no implementation-defined policy-identifiers allowed in this
6594 @strong{96}. Implementation-defined aspects of priority inversion. See
6598 Execution of a task cannot be preempted by the implementation processing
6599 of delay expirations for lower priority tasks.
6604 @strong{97}. Implementation defined task dispatching. See D.2.2(18).
6609 Tasks map to IRIX threads, and the dispatching policy is as defied by
6610 the IRIX implementation of threads.
6612 The policy is the same as that of the underlying threads implementation.
6617 @strong{98}. Implementation-defined @code{policy_identifiers} allowed
6618 in a pragma @code{Locking_Policy}. See D.3(4).
6621 The only implementation defined policy permitted in GNAT is
6622 @code{Inheritance_Locking}. On targets that support this policy, locking
6623 is implemented by inheritance, i.e.@: the task owning the lock operates
6624 at a priority equal to the highest priority of any task currently
6625 requesting the lock.
6630 @strong{99}. Default ceiling priorities. See D.3(10).
6633 The ceiling priority of protected objects of the type
6634 @code{System.Interrupt_Priority'Last} as described in the Ada 95
6635 Reference Manual D.3(10),
6640 @strong{100}. The ceiling of any protected object used internally by
6641 the implementation. See D.3(16).
6644 The ceiling priority of internal protected objects is
6645 @code{System.Priority'Last}.
6650 @strong{101}. Implementation-defined queuing policies. See D.4(1).
6653 There are no implementation-defined queueing policies.
6658 @strong{102}. On a multiprocessor, any conditions that cause the
6659 completion of an aborted construct to be delayed later than what is
6660 specified for a single processor. See D.6(3).
6663 The semantics for abort on a multi-processor is the same as on a single
6664 processor, there are no further delays.
6669 @strong{103}. Any operations that implicitly require heap storage
6670 allocation. See D.7(8).
6673 The only operation that implicitly requires heap storage allocation is
6679 @strong{104}. Implementation-defined aspects of pragma
6680 @code{Restrictions}. See D.7(20).
6683 There are no such implementation-defined aspects.
6688 @strong{105}. Implementation-defined aspects of package
6689 @code{Real_Time}. See D.8(17).
6692 There are no implementation defined aspects of package @code{Real_Time}.
6697 @strong{106}. Implementation-defined aspects of
6698 @code{delay_statements}. See D.9(8).
6701 Any difference greater than one microsecond will cause the task to be
6702 delayed (see D.9(7)).
6707 @strong{107}. The upper bound on the duration of interrupt blocking
6708 caused by the implementation. See D.12(5).
6711 The upper bound is determined by the underlying operating system. In
6712 no cases is it more than 10 milliseconds.
6717 @strong{108}. The means for creating and executing distributed
6721 The GLADE package provides a utility GNATDIST for creating and executing
6722 distributed programs. See the GLADE reference manual for further details.
6727 @strong{109}. Any events that can result in a partition becoming
6728 inaccessible. See E.1(7).
6731 See the GLADE reference manual for full details on such events.
6736 @strong{110}. The scheduling policies, treatment of priorities, and
6737 management of shared resources between partitions in certain cases. See
6741 See the GLADE reference manual for full details on these aspects of
6742 multi-partition execution.
6747 @strong{111}. Events that cause the version of a compilation unit to
6751 Editing the source file of a compilation unit, or the source files of
6752 any units on which it is dependent in a significant way cause the version
6753 to change. No other actions cause the version number to change. All changes
6754 are significant except those which affect only layout, capitalization or
6760 @strong{112}. Whether the execution of the remote subprogram is
6761 immediately aborted as a result of cancellation. See E.4(13).
6764 See the GLADE reference manual for details on the effect of abort in
6765 a distributed application.
6770 @strong{113}. Implementation-defined aspects of the PCS@. See E.5(25).
6773 See the GLADE reference manual for a full description of all implementation
6774 defined aspects of the PCS@.
6779 @strong{114}. Implementation-defined interfaces in the PCS@. See
6783 See the GLADE reference manual for a full description of all
6784 implementation defined interfaces.
6789 @strong{115}. The values of named numbers in the package
6790 @code{Decimal}. See F.2(7).
6802 @item Max_Decimal_Digits
6809 @strong{116}. The value of @code{Max_Picture_Length} in the package
6810 @code{Text_IO.Editing}. See F.3.3(16).
6818 @strong{117}. The value of @code{Max_Picture_Length} in the package
6819 @code{Wide_Text_IO.Editing}. See F.3.4(5).
6827 @strong{118}. The accuracy actually achieved by the complex elementary
6828 functions and by other complex arithmetic operations. See G.1(1).
6831 Standard library functions are used for the complex arithmetic
6832 operations. Only fast math mode is currently supported.
6837 @strong{119}. The sign of a zero result (or a component thereof) from
6838 any operator or function in @code{Numerics.Generic_Complex_Types}, when
6839 @code{Real'Signed_Zeros} is True. See G.1.1(53).
6842 The signs of zero values are as recommended by the relevant
6843 implementation advice.
6848 @strong{120}. The sign of a zero result (or a component thereof) from
6849 any operator or function in
6850 @code{Numerics.Generic_Complex_Elementary_Functions}, when
6851 @code{Real'Signed_Zeros} is @code{True}. See G.1.2(45).
6854 The signs of zero values are as recommended by the relevant
6855 implementation advice.
6860 @strong{121}. Whether the strict mode or the relaxed mode is the
6861 default. See G.2(2).
6864 The strict mode is the default. There is no separate relaxed mode. GNAT
6865 provides a highly efficient implementation of strict mode.
6870 @strong{122}. The result interval in certain cases of fixed-to-float
6871 conversion. See G.2.1(10).
6874 For cases where the result interval is implementation dependent, the
6875 accuracy is that provided by performing all operations in 64-bit IEEE
6876 floating-point format.
6881 @strong{123}. The result of a floating point arithmetic operation in
6882 overflow situations, when the @code{Machine_Overflows} attribute of the
6883 result type is @code{False}. See G.2.1(13).
6886 Infinite and Nan values are produced as dictated by the IEEE
6887 floating-point standard.
6892 @strong{124}. The result interval for division (or exponentiation by a
6893 negative exponent), when the floating point hardware implements division
6894 as multiplication by a reciprocal. See G.2.1(16).
6897 Not relevant, division is IEEE exact.
6902 @strong{125}. The definition of close result set, which determines the
6903 accuracy of certain fixed point multiplications and divisions. See
6907 Operations in the close result set are performed using IEEE long format
6908 floating-point arithmetic. The input operands are converted to
6909 floating-point, the operation is done in floating-point, and the result
6910 is converted to the target type.
6915 @strong{126}. Conditions on a @code{universal_real} operand of a fixed
6916 point multiplication or division for which the result shall be in the
6917 perfect result set. See G.2.3(22).
6920 The result is only defined to be in the perfect result set if the result
6921 can be computed by a single scaling operation involving a scale factor
6922 representable in 64-bits.
6927 @strong{127}. The result of a fixed point arithmetic operation in
6928 overflow situations, when the @code{Machine_Overflows} attribute of the
6929 result type is @code{False}. See G.2.3(27).
6932 Not relevant, @code{Machine_Overflows} is @code{True} for fixed-point
6938 @strong{128}. The result of an elementary function reference in
6939 overflow situations, when the @code{Machine_Overflows} attribute of the
6940 result type is @code{False}. See G.2.4(4).
6943 IEEE infinite and Nan values are produced as appropriate.
6948 @strong{129}. The value of the angle threshold, within which certain
6949 elementary functions, complex arithmetic operations, and complex
6950 elementary functions yield results conforming to a maximum relative
6951 error bound. See G.2.4(10).
6954 Information on this subject is not yet available.
6959 @strong{130}. The accuracy of certain elementary functions for
6960 parameters beyond the angle threshold. See G.2.4(10).
6963 Information on this subject is not yet available.
6968 @strong{131}. The result of a complex arithmetic operation or complex
6969 elementary function reference in overflow situations, when the
6970 @code{Machine_Overflows} attribute of the corresponding real type is
6971 @code{False}. See G.2.6(5).
6974 IEEE infinite and Nan values are produced as appropriate.
6979 @strong{132}. The accuracy of certain complex arithmetic operations and
6980 certain complex elementary functions for parameters (or components
6981 thereof) beyond the angle threshold. See G.2.6(8).
6984 Information on those subjects is not yet available.
6989 @strong{133}. Information regarding bounded errors and erroneous
6990 execution. See H.2(1).
6993 Information on this subject is not yet available.
6998 @strong{134}. Implementation-defined aspects of pragma
6999 @code{Inspection_Point}. See H.3.2(8).
7002 Pragma @code{Inspection_Point} ensures that the variable is live and can
7003 be examined by the debugger at the inspection point.
7008 @strong{135}. Implementation-defined aspects of pragma
7009 @code{Restrictions}. See H.4(25).
7012 There are no implementation-defined aspects of pragma @code{Restrictions}. The
7013 use of pragma @code{Restrictions [No_Exceptions]} has no effect on the
7014 generated code. Checks must suppressed by use of pragma @code{Suppress}.
7019 @strong{136}. Any restrictions on pragma @code{Restrictions}. See
7023 There are no restrictions on pragma @code{Restrictions}.
7025 @node Intrinsic Subprograms
7026 @chapter Intrinsic Subprograms
7027 @cindex Intrinsic Subprograms
7030 * Intrinsic Operators::
7031 * Enclosing_Entity::
7032 * Exception_Information::
7033 * Exception_Message::
7041 * Shift_Right_Arithmetic::
7045 GNAT allows a user application program to write the declaration:
7048 pragma Import (Intrinsic, name);
7052 providing that the name corresponds to one of the implemented intrinsic
7053 subprograms in GNAT, and that the parameter profile of the referenced
7054 subprogram meets the requirements. This chapter describes the set of
7055 implemented intrinsic subprograms, and the requirements on parameter profiles.
7056 Note that no body is supplied; as with other uses of pragma Import, the
7057 body is supplied elsewhere (in this case by the compiler itself). Note
7058 that any use of this feature is potentially non-portable, since the
7059 Ada standard does not require Ada compilers to implement this feature.
7061 @node Intrinsic Operators
7062 @section Intrinsic Operators
7063 @cindex Intrinsic operator
7066 All the predefined numeric operators in package Standard
7067 in @code{pragma Import (Intrinsic,..)}
7068 declarations. In the binary operator case, the operands must have the same
7069 size. The operand or operands must also be appropriate for
7070 the operator. For example, for addition, the operands must
7071 both be floating-point or both be fixed-point, and the
7072 right operand for @code{"**"} must have a root type of
7073 @code{Standard.Integer'Base}.
7074 You can use an intrinsic operator declaration as in the following example:
7077 type Int1 is new Integer;
7078 type Int2 is new Integer;
7080 function "+" (X1 : Int1; X2 : Int2) return Int1;
7081 function "+" (X1 : Int1; X2 : Int2) return Int2;
7082 pragma Import (Intrinsic, "+");
7086 This declaration would permit ``mixed mode'' arithmetic on items
7087 of the differing types @code{Int1} and @code{Int2}.
7088 It is also possible to specify such operators for private types, if the
7089 full views are appropriate arithmetic types.
7091 @node Enclosing_Entity
7092 @section Enclosing_Entity
7093 @cindex Enclosing_Entity
7095 This intrinsic subprogram is used in the implementation of the
7096 library routine @code{GNAT.Source_Info}. The only useful use of the
7097 intrinsic import in this case is the one in this unit, so an
7098 application program should simply call the function
7099 @code{GNAT.Source_Info.Enclosing_Entity} to obtain the name of
7100 the current subprogram, package, task, entry, or protected subprogram.
7102 @node Exception_Information
7103 @section Exception_Information
7104 @cindex Exception_Information'
7106 This intrinsic subprogram is used in the implementation of the
7107 library routine @code{GNAT.Current_Exception}. The only useful
7108 use of the intrinsic import in this case is the one in this unit,
7109 so an application program should simply call the function
7110 @code{GNAT.Current_Exception.Exception_Information} to obtain
7111 the exception information associated with the current exception.
7113 @node Exception_Message
7114 @section Exception_Message
7115 @cindex Exception_Message
7117 This intrinsic subprogram is used in the implementation of the
7118 library routine @code{GNAT.Current_Exception}. The only useful
7119 use of the intrinsic import in this case is the one in this unit,
7120 so an application program should simply call the function
7121 @code{GNAT.Current_Exception.Exception_Message} to obtain
7122 the message associated with the current exception.
7124 @node Exception_Name
7125 @section Exception_Name
7126 @cindex Exception_Name
7128 This intrinsic subprogram is used in the implementation of the
7129 library routine @code{GNAT.Current_Exception}. The only useful
7130 use of the intrinsic import in this case is the one in this unit,
7131 so an application program should simply call the function
7132 @code{GNAT.Current_Exception.Exception_Name} to obtain
7133 the name of the current exception.
7139 This intrinsic subprogram is used in the implementation of the
7140 library routine @code{GNAT.Source_Info}. The only useful use of the
7141 intrinsic import in this case is the one in this unit, so an
7142 application program should simply call the function
7143 @code{GNAT.Source_Info.File} to obtain the name of the current
7150 This intrinsic subprogram is used in the implementation of the
7151 library routine @code{GNAT.Source_Info}. The only useful use of the
7152 intrinsic import in this case is the one in this unit, so an
7153 application program should simply call the function
7154 @code{GNAT.Source_Info.Line} to obtain the number of the current
7158 @section Rotate_Left
7161 In standard Ada 95, the @code{Rotate_Left} function is available only
7162 for the predefined modular types in package @code{Interfaces}. However, in
7163 GNAT it is possible to define a Rotate_Left function for a user
7164 defined modular type or any signed integer type as in this example:
7168 (Value : My_Modular_Type;
7170 return My_Modular_Type;
7174 The requirements are that the profile be exactly as in the example
7175 above. The only modifications allowed are in the formal parameter
7176 names, and in the type of @code{Value} and the return type, which
7177 must be the same, and must be either a signed integer type, or
7178 a modular integer type with a binary modulus, and the size must
7179 be 8. 16, 32 or 64 bits.
7182 @section Rotate_Right
7183 @cindex Rotate_Right
7185 A @code{Rotate_Right} function can be defined for any user defined
7186 binary modular integer type, or signed integer type, as described
7187 above for @code{Rotate_Left}.
7193 A @code{Shift_Left} function can be defined for any user defined
7194 binary modular integer type, or signed integer type, as described
7195 above for @code{Rotate_Left}.
7198 @section Shift_Right
7201 A @code{Shift_Right} function can be defined for any user defined
7202 binary modular integer type, or signed integer type, as described
7203 above for @code{Rotate_Left}.
7205 @node Shift_Right_Arithmetic
7206 @section Shift_Right_Arithmetic
7207 @cindex Shift_Right_Arithmetic
7209 A @code{Shift_Right_Arithmetic} function can be defined for any user
7210 defined binary modular integer type, or signed integer type, as described
7211 above for @code{Rotate_Left}.
7213 @node Source_Location
7214 @section Source_Location
7215 @cindex Source_Location
7217 This intrinsic subprogram is used in the implementation of the
7218 library routine @code{GNAT.Source_Info}. The only useful use of the
7219 intrinsic import in this case is the one in this unit, so an
7220 application program should simply call the function
7221 @code{GNAT.Source_Info.Source_Location} to obtain the current
7222 source file location.
7224 @node Representation Clauses and Pragmas
7225 @chapter Representation Clauses and Pragmas
7226 @cindex Representation Clauses
7229 * Alignment Clauses::
7231 * Storage_Size Clauses::
7232 * Size of Variant Record Objects::
7233 * Biased Representation ::
7234 * Value_Size and Object_Size Clauses::
7235 * Component_Size Clauses::
7236 * Bit_Order Clauses::
7237 * Effect of Bit_Order on Byte Ordering::
7238 * Pragma Pack for Arrays::
7239 * Pragma Pack for Records::
7240 * Record Representation Clauses::
7241 * Enumeration Clauses::
7243 * Effect of Convention on Representation::
7244 * Determining the Representations chosen by GNAT::
7248 @cindex Representation Clause
7249 @cindex Representation Pragma
7250 @cindex Pragma, representation
7251 This section describes the representation clauses accepted by GNAT, and
7252 their effect on the representation of corresponding data objects.
7254 GNAT fully implements Annex C (Systems Programming). This means that all
7255 the implementation advice sections in chapter 13 are fully implemented.
7256 However, these sections only require a minimal level of support for
7257 representation clauses. GNAT provides much more extensive capabilities,
7258 and this section describes the additional capabilities provided.
7260 @node Alignment Clauses
7261 @section Alignment Clauses
7262 @cindex Alignment Clause
7265 GNAT requires that all alignment clauses specify a power of 2, and all
7266 default alignments are always a power of 2. The default alignment
7267 values are as follows:
7270 @item Primitive Types
7271 For primitive types, the alignment is the maximum of the actual size of
7272 objects of the type, and the maximum alignment supported by the target.
7273 For example, for type Long_Float, the object size is 8 bytes, and the
7274 default alignment will be 8 on any target that supports alignments
7275 this large, but on some targets, the maximum alignment may be smaller
7276 than 8, in which case objects of type Long_Float will be maximally
7280 For arrays, the alignment is equal to the alignment of the component type
7281 for the normal case where no packing or component size is given. If the
7282 array is packed, and the packing is effective (see separate section on
7283 packed arrays), then the alignment will be one for long packed arrays,
7284 or arrays whose length is not known at compile time. For short packed
7285 arrays, which are handled internally as modular types, the alignment
7286 will be as described for primitive types, e.g.@: a packed array of length
7287 31 bits will have an object size of four bytes, and an alignment of 4.
7290 For the normal non-packed case, the alignment of a record is equal to
7291 the maximum alignment of any of its components. For tagged records, this
7292 includes the implicit access type used for the tag. If a pragma @code{Pack} is
7293 used and all fields are packable (see separate section on pragma @code{Pack}),
7294 then the resulting alignment is 1.
7296 A special case is when the size of the record is given explicitly, or a
7297 full record representation clause is given, and the size of the record
7298 is 2, 4, or 8 bytes. In this case, an alignment is chosen to match the
7299 size of the record. For example, if we have:
7302 type Small is record
7308 then the default alignment of the record type @code{Small} is 2, not 1. This
7309 leads to more efficient code when the record is treated as a unit, and also
7310 allows the type to specified as @code{Atomic} on architectures requiring
7316 An alignment clause may
7317 always specify a larger alignment than the default value, up to some
7318 maximum value dependent on the target (obtainable by using the
7319 attribute reference System'Maximum_Alignment). The only case in which
7320 it is permissible to specify a smaller alignment than the default value
7321 is in the case of a record for which a record representation clause is
7322 given. In this case, packable fields for which a component clause is
7323 given still result in a default alignment corresponding to the original
7324 type, but this may be overridden, since these components in fact only
7325 require an alignment of one byte. For example, given
7333 a at 0 range 0 .. 31;
7336 for v'alignment use 1;
7340 @cindex Alignment, default
7341 The default alignment for the type @code{v} is 4, as a result of the
7342 integer field in the record, but since this field is placed with a
7343 component clause, it is permissible, as shown, to override the default
7344 alignment of the record to a smaller value.
7347 @section Size Clauses
7351 The default size of types is as specified in the reference manual. For
7352 objects, GNAT will generally increase the type size so that the object
7353 size is a multiple of storage units, and also a multiple of the
7354 alignment. For example
7357 type Smallint is range 1 .. 6;
7366 In this example, @code{Smallint}
7367 has a size of 3, as specified by the RM rules,
7368 but objects of this type will have a size of 8,
7369 since objects by default occupy an integral number
7370 of storage units. On some targets, notably older
7371 versions of the Digital Alpha, the size of stand
7372 alone objects of this type may be 32, reflecting
7373 the inability of the hardware to do byte load/stores.
7375 Similarly, the size of type @code{Rec} is 40 bits, but
7376 the alignment is 4, so objects of this type will have
7377 their size increased to 64 bits so that it is a multiple
7378 of the alignment. The reason for this decision, which is
7379 in accordance with the specific note in RM 13.3(43):
7382 A Size clause should be supported for an object if the specified
7383 Size is at least as large as its subtype's Size, and corresponds
7384 to a size in storage elements that is a multiple of the object's
7385 Alignment (if the Alignment is nonzero).
7389 An explicit size clause may be used to override the default size by
7390 increasing it. For example, if we have:
7393 type My_Boolean is new Boolean;
7394 for My_Boolean'Size use 32;
7398 then objects of this type will always be 32 bits long. In the case of
7399 discrete types, the size can be increased up to 64 bits, with the effect
7400 that the entire specified field is used to hold the value, sign- or
7401 zero-extended as appropriate. If more than 64 bits is specified, then
7402 padding space is allocated after the value, and a warning is issued that
7403 there are unused bits.
7405 Similarly the size of records and arrays may be increased, and the effect
7406 is to add padding bits after the value. This also causes a warning message
7409 The largest Size value permitted in GNAT is 2**32@minus{}1. Since this is a
7410 Size in bits, this corresponds to an object of size 256 megabytes (minus
7411 one). This limitation is true on all targets. The reason for this
7412 limitation is that it improves the quality of the code in many cases
7413 if it is known that a Size value can be accommodated in an object of
7416 @node Storage_Size Clauses
7417 @section Storage_Size Clauses
7418 @cindex Storage_Size Clause
7421 For tasks, the @code{Storage_Size} clause specifies the amount of space
7422 to be allocated for the task stack. This cannot be extended, and if the
7423 stack is exhausted, then @code{Storage_Error} will be raised if stack
7424 checking is enabled. If the default size of 20K bytes is insufficient,
7425 then you need to use a @code{Storage_Size} attribute definition clause,
7426 or a @code{Storage_Size} pragma in the task definition to set the
7427 appropriate required size. A useful technique is to include in every
7428 task definition a pragma of the form:
7431 pragma Storage_Size (Default_Stack_Size);
7435 Then Default_Stack_Size can be defined in a global package, and modified
7436 as required. Any tasks requiring different task stack sizes from the
7437 default can have an appropriate alternative reference in the pragma.
7439 For access types, the @code{Storage_Size} clause specifies the maximum
7440 space available for allocation of objects of the type. If this space is
7441 exceeded then @code{Storage_Error} will be raised by an allocation attempt.
7442 In the case where the access type is declared local to a subprogram, the
7443 use of a @code{Storage_Size} clause triggers automatic use of a special
7444 predefined storage pool (@code{System.Pool_Size}) that ensures that all
7445 space for the pool is automatically reclaimed on exit from the scope in
7446 which the type is declared.
7448 A special case recognized by the compiler is the specification of a
7449 @code{Storage_Size} of zero for an access type. This means that no
7450 items can be allocated from the pool, and this is recognized at compile
7451 time, and all the overhead normally associated with maintaining a fixed
7452 size storage pool is eliminated. Consider the following example:
7456 type R is array (Natural) of Character;
7457 type P is access all R;
7458 for P'Storage_Size use 0;
7459 -- Above access type intended only for interfacing purposes
7463 procedure g (m : P);
7464 pragma Import (C, g);
7475 As indicated in this example, these dummy storage pools are often useful in
7476 connection with interfacing where no object will ever be allocated. If you
7477 compile the above example, you get the warning:
7480 p.adb:16:09: warning: allocation from empty storage pool
7481 p.adb:16:09: warning: Storage_Error will be raised at run time
7485 Of course in practice, there will not be any explicit allocators in the
7486 case of such an access declaration.
7488 @node Size of Variant Record Objects
7489 @section Size of Variant Record Objects
7490 @cindex Size, variant record objects
7491 @cindex Variant record objects, size
7494 An issue arises in the case of variant record objects of whether Size gives
7495 information about a particular variant, or the maximum size required
7496 for any variant. Consider the following program
7499 with Text_IO; use Text_IO;
7501 type R1 (A : Boolean := False) is record
7503 when True => X : Character;
7512 Put_Line (Integer'Image (V1'Size));
7513 Put_Line (Integer'Image (V2'Size));
7518 Here we are dealing with a variant record, where the True variant
7519 requires 16 bits, and the False variant requires 8 bits.
7520 In the above example, both V1 and V2 contain the False variant,
7521 which is only 8 bits long. However, the result of running the
7530 The reason for the difference here is that the discriminant value of
7531 V1 is fixed, and will always be False. It is not possible to assign
7532 a True variant value to V1, therefore 8 bits is sufficient. On the
7533 other hand, in the case of V2, the initial discriminant value is
7534 False (from the default), but it is possible to assign a True
7535 variant value to V2, therefore 16 bits must be allocated for V2
7536 in the general case, even fewer bits may be needed at any particular
7537 point during the program execution.
7539 As can be seen from the output of this program, the @code{'Size}
7540 attribute applied to such an object in GNAT gives the actual allocated
7541 size of the variable, which is the largest size of any of the variants.
7542 The Ada Reference Manual is not completely clear on what choice should
7543 be made here, but the GNAT behavior seems most consistent with the
7544 language in the RM@.
7546 In some cases, it may be desirable to obtain the size of the current
7547 variant, rather than the size of the largest variant. This can be
7548 achieved in GNAT by making use of the fact that in the case of a
7549 subprogram parameter, GNAT does indeed return the size of the current
7550 variant (because a subprogram has no way of knowing how much space
7551 is actually allocated for the actual).
7553 Consider the following modified version of the above program:
7556 with Text_IO; use Text_IO;
7558 type R1 (A : Boolean := False) is record
7560 when True => X : Character;
7567 function Size (V : R1) return Integer is
7573 Put_Line (Integer'Image (V2'Size));
7574 Put_Line (Integer'IMage (Size (V2)));
7576 Put_Line (Integer'Image (V2'Size));
7577 Put_Line (Integer'IMage (Size (V2)));
7582 The output from this program is
7592 Here we see that while the @code{'Size} attribute always returns
7593 the maximum size, regardless of the current variant value, the
7594 @code{Size} function does indeed return the size of the current
7597 @node Biased Representation
7598 @section Biased Representation
7599 @cindex Size for biased representation
7600 @cindex Biased representation
7603 In the case of scalars with a range starting at other than zero, it is
7604 possible in some cases to specify a size smaller than the default minimum
7605 value, and in such cases, GNAT uses an unsigned biased representation,
7606 in which zero is used to represent the lower bound, and successive values
7607 represent successive values of the type.
7609 For example, suppose we have the declaration:
7612 type Small is range -7 .. -4;
7613 for Small'Size use 2;
7617 Although the default size of type @code{Small} is 4, the @code{Size}
7618 clause is accepted by GNAT and results in the following representation
7622 -7 is represented as 2#00#
7623 -6 is represented as 2#01#
7624 -5 is represented as 2#10#
7625 -4 is represented as 2#11#
7629 Biased representation is only used if the specified @code{Size} clause
7630 cannot be accepted in any other manner. These reduced sizes that force
7631 biased representation can be used for all discrete types except for
7632 enumeration types for which a representation clause is given.
7634 @node Value_Size and Object_Size Clauses
7635 @section Value_Size and Object_Size Clauses
7638 @cindex Size, of objects
7641 In Ada 95, the @code{Size} of a discrete type is the minimum number of bits
7642 required to hold values of the type. Although this interpretation was
7643 allowed in Ada 83, it was not required, and this requirement in practice
7644 can cause some significant difficulties. For example, in most Ada 83
7645 compilers, @code{Natural'Size} was 32. However, in Ada-95,
7646 @code{Natural'Size} is
7647 typically 31. This means that code may change in behavior when moving
7648 from Ada 83 to Ada 95. For example, consider:
7657 for A use at 0 range 0 .. Natural'Size - 1;
7658 for B use at 0 range Natural'Size .. 2 * Natural'Size - 1;
7663 In the above code, since the typical size of @code{Natural} objects
7664 is 32 bits and @code{Natural'Size} is 31, the above code can cause
7665 unexpected inefficient packing in Ada 95, and in general there are
7666 surprising cases where the fact that the object size can exceed the
7667 size of the type causes surprises.
7669 To help get around this problem GNAT provides two implementation
7670 dependent attributes @code{Value_Size} and @code{Object_Size}. When
7671 applied to a type, these attributes yield the size of the type
7672 (corresponding to the RM defined size attribute), and the size of
7673 objects of the type respectively.
7675 The @code{Object_Size} is used for determining the default size of
7676 objects and components. This size value can be referred to using the
7677 @code{Object_Size} attribute. The phrase ``is used'' here means that it is
7678 the basis of the determination of the size. The backend is free to
7679 pad this up if necessary for efficiency, e.g.@: an 8-bit stand-alone
7680 character might be stored in 32 bits on a machine with no efficient
7681 byte access instructions such as the Alpha.
7683 The default rules for the value of @code{Object_Size} for fixed-point and
7684 discrete types are as follows:
7688 The @code{Object_Size} for base subtypes reflect the natural hardware
7689 size in bits (run the utility @code{gnatpsta} to find those values for numeric types).
7690 Enumeration types and fixed-point base subtypes have 8, 16, 32 or 64
7691 bits for this size, depending on the range of values to be stored.
7694 The @code{Object_Size} of a subtype is the same as the
7695 @code{Object_Size} of
7696 the type from which it is obtained.
7699 The @code{Object_Size} of a derived base type is copied from the parent
7700 base type, and the @code{Object_Size} of a derived first subtype is copied
7701 from the parent first subtype.
7705 The @code{Value_Size} attribute
7706 is the number of bits required to store a value
7707 of the type. This size can be referred to using the @code{Value_Size}
7708 attribute. This value is used to determine how tightly to pack
7709 records or arrays with components of this type, and also affects
7710 the semantics of unchecked conversion (unchecked conversions where
7711 the @code{Value_Size} values differ generate a warning, and are potentially
7714 The default rules for the value of @code{Value_Size} are as follows:
7718 The @code{Value_Size} for a base subtype is the minimum number of bits
7719 required to store all values of the type (including the sign bit
7720 only if negative values are possible).
7723 If a subtype statically matches the first subtype of a given type, then it has
7724 by default the same @code{Value_Size} as the first subtype. This is a
7725 consequence of RM 13.1(14) (``if two subtypes statically match,
7726 then their subtype-specific aspects are the same''.)
7729 All other subtypes have a @code{Value_Size} corresponding to the minimum
7730 number of bits required to store all values of the subtype. For
7731 dynamic bounds, it is assumed that the value can range down or up
7732 to the corresponding bound of the ancestor
7736 The RM defined attribute @code{Size} corresponds to the
7737 @code{Value_Size} attribute.
7739 The @code{Size} attribute may be defined for a first-named subtype. This sets
7740 the @code{Value_Size} of
7741 the first-named subtype to the given value, and the
7742 @code{Object_Size} of this first-named subtype to the given value padded up
7743 to an appropriate boundary. It is a consequence of the default rules
7744 above that this @code{Object_Size} will apply to all further subtypes. On the
7745 other hand, @code{Value_Size} is affected only for the first subtype, any
7746 dynamic subtypes obtained from it directly, and any statically matching
7747 subtypes. The @code{Value_Size} of any other static subtypes is not affected.
7749 @code{Value_Size} and
7750 @code{Object_Size} may be explicitly set for any subtype using
7751 an attribute definition clause. Note that the use of these attributes
7752 can cause the RM 13.1(14) rule to be violated. If two access types
7753 reference aliased objects whose subtypes have differing @code{Object_Size}
7754 values as a result of explicit attribute definition clauses, then it
7755 is erroneous to convert from one access subtype to the other.
7757 At the implementation level, Esize stores the Object_SIze and the
7758 RM_Size field stores the @code{Value_Size} (and hence the value of the
7759 @code{Size} attribute,
7760 which, as noted above, is equivalent to @code{Value_Size}).
7762 To get a feel for the difference, consider the following examples (note
7763 that in each case the base is short_short_integer with a size of 8):
7766 Object_Size Value_Size
7768 type x1 is range 0 .. 5; 8 3
7770 type x2 is range 0 .. 5;
7771 for x2'size use 12; 12 12
7773 subtype x3 is x2 range 0 .. 3; 12 2
7775 subtype x4 is x2'base range 0 .. 10; 8 4
7777 subtype x5 is x2 range 0 .. dynamic; 12 (7)
7779 subtype x6 is x2'base range 0 .. dynamic; 8 (7)
7784 Note: the entries marked (7) are not actually specified by the Ada 95 RM,
7785 but it seems in the spirit of the RM rules to allocate the minimum number
7786 of bits known to be large enough to hold the given range of values.
7788 So far, so good, but GNAT has to obey the RM rules, so the question is
7789 under what conditions must the RM @code{Size} be used.
7790 The following is a list
7791 of the occasions on which the RM @code{Size} must be used:
7795 Component size for packed arrays or records
7798 Value of the attribute @code{Size} for a type
7801 Warning about sizes not matching for unchecked conversion
7805 For types other than discrete and fixed-point types, the @code{Object_Size}
7806 and Value_Size are the same (and equivalent to the RM attribute @code{Size}).
7807 Only @code{Size} may be specified for such types.
7809 @node Component_Size Clauses
7810 @section Component_Size Clauses
7811 @cindex Component_Size Clause
7814 Normally, the value specified in a component clause must be consistent
7815 with the subtype of the array component with regard to size and alignment.
7816 In other words, the value specified must be at least equal to the size
7817 of this subtype, and must be a multiple of the alignment value.
7819 In addition, component size clauses are allowed which cause the array
7820 to be packed, by specifying a smaller value. The cases in which this
7821 is allowed are for component size values in the range 1 through 63. The value
7822 specified must not be smaller than the Size of the subtype. GNAT will
7823 accurately honor all packing requests in this range. For example, if
7827 type r is array (1 .. 8) of Natural;
7832 then the resulting array has a length of 31 bytes (248 bits = 8 * 31).
7833 Of course access to the components of such an array is considerably
7834 less efficient than if the natural component size of 32 is used.
7836 @node Bit_Order Clauses
7837 @section Bit_Order Clauses
7838 @cindex Bit_Order Clause
7839 @cindex bit ordering
7840 @cindex ordering, of bits
7843 For record subtypes, GNAT permits the specification of the @code{Bit_Order}
7844 attribute. The specification may either correspond to the default bit
7845 order for the target, in which case the specification has no effect and
7846 places no additional restrictions, or it may be for the non-standard
7847 setting (that is the opposite of the default).
7849 In the case where the non-standard value is specified, the effect is
7850 to renumber bits within each byte, but the ordering of bytes is not
7851 affected. There are certain
7852 restrictions placed on component clauses as follows:
7856 @item Components fitting within a single storage unit.
7858 These are unrestricted, and the effect is merely to renumber bits. For
7859 example if we are on a little-endian machine with @code{Low_Order_First}
7860 being the default, then the following two declarations have exactly
7866 B : Integer range 1 .. 120;
7870 A at 0 range 0 .. 0;
7871 B at 0 range 1 .. 7;
7876 B : Integer range 1 .. 120;
7879 for R2'Bit_Order use High_Order_First;
7882 A at 0 range 7 .. 7;
7883 B at 0 range 0 .. 6;
7888 The useful application here is to write the second declaration with the
7889 @code{Bit_Order} attribute definition clause, and know that it will be treated
7890 the same, regardless of whether the target is little-endian or big-endian.
7892 @item Components occupying an integral number of bytes.
7894 These are components that exactly fit in two or more bytes. Such component
7895 declarations are allowed, but have no effect, since it is important to realize
7896 that the @code{Bit_Order} specification does not affect the ordering of bytes.
7897 In particular, the following attempt at getting an endian-independent integer
7905 for R2'Bit_Order use High_Order_First;
7908 A at 0 range 0 .. 31;
7913 This declaration will result in a little-endian integer on a
7914 little-endian machine, and a big-endian integer on a big-endian machine.
7915 If byte flipping is required for interoperability between big- and
7916 little-endian machines, this must be explicitly programmed. This capability
7917 is not provided by @code{Bit_Order}.
7919 @item Components that are positioned across byte boundaries
7921 but do not occupy an integral number of bytes. Given that bytes are not
7922 reordered, such fields would occupy a non-contiguous sequence of bits
7923 in memory, requiring non-trivial code to reassemble. They are for this
7924 reason not permitted, and any component clause specifying such a layout
7925 will be flagged as illegal by GNAT@.
7930 Since the misconception that Bit_Order automatically deals with all
7931 endian-related incompatibilities is a common one, the specification of
7932 a component field that is an integral number of bytes will always
7933 generate a warning. This warning may be suppressed using
7934 @code{pragma Suppress} if desired. The following section contains additional
7935 details regarding the issue of byte ordering.
7937 @node Effect of Bit_Order on Byte Ordering
7938 @section Effect of Bit_Order on Byte Ordering
7939 @cindex byte ordering
7940 @cindex ordering, of bytes
7943 In this section we will review the effect of the @code{Bit_Order} attribute
7944 definition clause on byte ordering. Briefly, it has no effect at all, but
7945 a detailed example will be helpful. Before giving this
7946 example, let us review the precise
7947 definition of the effect of defining @code{Bit_Order}. The effect of a
7948 non-standard bit order is described in section 15.5.3 of the Ada
7952 2 A bit ordering is a method of interpreting the meaning of
7953 the storage place attributes.
7957 To understand the precise definition of storage place attributes in
7958 this context, we visit section 13.5.1 of the manual:
7961 13 A record_representation_clause (without the mod_clause)
7962 specifies the layout. The storage place attributes (see 13.5.2)
7963 are taken from the values of the position, first_bit, and last_bit
7964 expressions after normalizing those values so that first_bit is
7965 less than Storage_Unit.
7969 The critical point here is that storage places are taken from
7970 the values after normalization, not before. So the @code{Bit_Order}
7971 interpretation applies to normalized values. The interpretation
7972 is described in the later part of the 15.5.3 paragraph:
7975 2 A bit ordering is a method of interpreting the meaning of
7976 the storage place attributes. High_Order_First (known in the
7977 vernacular as ``big endian'') means that the first bit of a
7978 storage element (bit 0) is the most significant bit (interpreting
7979 the sequence of bits that represent a component as an unsigned
7980 integer value). Low_Order_First (known in the vernacular as
7981 ``little endian'') means the opposite: the first bit is the
7986 Note that the numbering is with respect to the bits of a storage
7987 unit. In other words, the specification affects only the numbering
7988 of bits within a single storage unit.
7990 We can make the effect clearer by giving an example.
7992 Suppose that we have an external device which presents two bytes, the first
7993 byte presented, which is the first (low addressed byte) of the two byte
7994 record is called Master, and the second byte is called Slave.
7996 The left most (most significant bit is called Control for each byte, and
7997 the remaining 7 bits are called V1, V2, @dots{} V7, where V7 is the rightmost
7998 (least significant) bit.
8000 On a big-endian machine, we can write the following representation clause
8004 Master_Control : Bit;
8012 Slave_Control : Bit;
8023 Master_Control at 0 range 0 .. 0;
8024 Master_V1 at 0 range 1 .. 1;
8025 Master_V2 at 0 range 2 .. 2;
8026 Master_V3 at 0 range 3 .. 3;
8027 Master_V4 at 0 range 4 .. 4;
8028 Master_V5 at 0 range 5 .. 5;
8029 Master_V6 at 0 range 6 .. 6;
8030 Master_V7 at 0 range 7 .. 7;
8031 Slave_Control at 1 range 0 .. 0;
8032 Slave_V1 at 1 range 1 .. 1;
8033 Slave_V2 at 1 range 2 .. 2;
8034 Slave_V3 at 1 range 3 .. 3;
8035 Slave_V4 at 1 range 4 .. 4;
8036 Slave_V5 at 1 range 5 .. 5;
8037 Slave_V6 at 1 range 6 .. 6;
8038 Slave_V7 at 1 range 7 .. 7;
8043 Now if we move this to a little endian machine, then the bit ordering within
8044 the byte is backwards, so we have to rewrite the record rep clause as:
8048 Master_Control at 0 range 7 .. 7;
8049 Master_V1 at 0 range 6 .. 6;
8050 Master_V2 at 0 range 5 .. 5;
8051 Master_V3 at 0 range 4 .. 4;
8052 Master_V4 at 0 range 3 .. 3;
8053 Master_V5 at 0 range 2 .. 2;
8054 Master_V6 at 0 range 1 .. 1;
8055 Master_V7 at 0 range 0 .. 0;
8056 Slave_Control at 1 range 7 .. 7;
8057 Slave_V1 at 1 range 6 .. 6;
8058 Slave_V2 at 1 range 5 .. 5;
8059 Slave_V3 at 1 range 4 .. 4;
8060 Slave_V4 at 1 range 3 .. 3;
8061 Slave_V5 at 1 range 2 .. 2;
8062 Slave_V6 at 1 range 1 .. 1;
8063 Slave_V7 at 1 range 0 .. 0;
8067 It is a nuisance to have to rewrite the clause, especially if
8068 the code has to be maintained on both machines. However,
8069 this is a case that we can handle with the
8070 @code{Bit_Order} attribute if it is implemented.
8071 Note that the implementation is not required on byte addressed
8072 machines, but it is indeed implemented in GNAT.
8073 This means that we can simply use the
8074 first record clause, together with the declaration
8077 for Data'Bit_Order use High_Order_First;
8081 and the effect is what is desired, namely the layout is exactly the same,
8082 independent of whether the code is compiled on a big-endian or little-endian
8085 The important point to understand is that byte ordering is not affected.
8086 A @code{Bit_Order} attribute definition never affects which byte a field
8087 ends up in, only where it ends up in that byte.
8088 To make this clear, let us rewrite the record rep clause of the previous
8092 for Data'Bit_Order use High_Order_First;
8094 Master_Control at 0 range 0 .. 0;
8095 Master_V1 at 0 range 1 .. 1;
8096 Master_V2 at 0 range 2 .. 2;
8097 Master_V3 at 0 range 3 .. 3;
8098 Master_V4 at 0 range 4 .. 4;
8099 Master_V5 at 0 range 5 .. 5;
8100 Master_V6 at 0 range 6 .. 6;
8101 Master_V7 at 0 range 7 .. 7;
8102 Slave_Control at 0 range 8 .. 8;
8103 Slave_V1 at 0 range 9 .. 9;
8104 Slave_V2 at 0 range 10 .. 10;
8105 Slave_V3 at 0 range 11 .. 11;
8106 Slave_V4 at 0 range 12 .. 12;
8107 Slave_V5 at 0 range 13 .. 13;
8108 Slave_V6 at 0 range 14 .. 14;
8109 Slave_V7 at 0 range 15 .. 15;
8114 This is exactly equivalent to saying (a repeat of the first example):
8117 for Data'Bit_Order use High_Order_First;
8119 Master_Control at 0 range 0 .. 0;
8120 Master_V1 at 0 range 1 .. 1;
8121 Master_V2 at 0 range 2 .. 2;
8122 Master_V3 at 0 range 3 .. 3;
8123 Master_V4 at 0 range 4 .. 4;
8124 Master_V5 at 0 range 5 .. 5;
8125 Master_V6 at 0 range 6 .. 6;
8126 Master_V7 at 0 range 7 .. 7;
8127 Slave_Control at 1 range 0 .. 0;
8128 Slave_V1 at 1 range 1 .. 1;
8129 Slave_V2 at 1 range 2 .. 2;
8130 Slave_V3 at 1 range 3 .. 3;
8131 Slave_V4 at 1 range 4 .. 4;
8132 Slave_V5 at 1 range 5 .. 5;
8133 Slave_V6 at 1 range 6 .. 6;
8134 Slave_V7 at 1 range 7 .. 7;
8139 Why are they equivalent? Well take a specific field, the @code{Slave_V2}
8140 field. The storage place attributes are obtained by normalizing the
8141 values given so that the @code{First_Bit} value is less than 8. After
8142 nromalizing the values (0,10,10) we get (1,2,2) which is exactly what
8143 we specified in the other case.
8145 Now one might expect that the @code{Bit_Order} attribute might affect
8146 bit numbering within the entire record component (two bytes in this
8147 case, thus affecting which byte fields end up in), but that is not
8148 the way this feature is defined, it only affects numbering of bits,
8149 not which byte they end up in.
8151 Consequently it never makes sense to specify a starting bit number
8152 greater than 7 (for a byte addressable field) if an attribute
8153 definition for @code{Bit_Order} has been given, and indeed it
8154 may be actively confusing to specify such a value, so the compiler
8155 generates a warning for such usage.
8157 If you do need to control byte ordering then appropriate conditional
8158 values must be used. If in our example, the slave byte came first on
8159 some machines we might write:
8162 Master_Byte_First constant Boolean := @dots{};
8164 Master_Byte : constant Natural :=
8165 1 - Boolean'Pos (Master_Byte_First);
8166 Slave_Byte : constant Natural :=
8167 Boolean'Pos (Master_Byte_First);
8169 for Data'Bit_Order use High_Order_First;
8171 Master_Control at Master_Byte range 0 .. 0;
8172 Master_V1 at Master_Byte range 1 .. 1;
8173 Master_V2 at Master_Byte range 2 .. 2;
8174 Master_V3 at Master_Byte range 3 .. 3;
8175 Master_V4 at Master_Byte range 4 .. 4;
8176 Master_V5 at Master_Byte range 5 .. 5;
8177 Master_V6 at Master_Byte range 6 .. 6;
8178 Master_V7 at Master_Byte range 7 .. 7;
8179 Slave_Control at Slave_Byte range 0 .. 0;
8180 Slave_V1 at Slave_Byte range 1 .. 1;
8181 Slave_V2 at Slave_Byte range 2 .. 2;
8182 Slave_V3 at Slave_Byte range 3 .. 3;
8183 Slave_V4 at Slave_Byte range 4 .. 4;
8184 Slave_V5 at Slave_Byte range 5 .. 5;
8185 Slave_V6 at Slave_Byte range 6 .. 6;
8186 Slave_V7 at Slave_Byte range 7 .. 7;
8191 Now to switch between machines, all that is necessary is
8192 to set the boolean constant @code{Master_Byte_First} in
8193 an appropriate manner.
8195 @node Pragma Pack for Arrays
8196 @section Pragma Pack for Arrays
8197 @cindex Pragma Pack (for arrays)
8200 Pragma @code{Pack} applied to an array has no effect unless the component type
8201 is packable. For a component type to be packable, it must be one of the
8208 Any fixed-point type
8210 Any type whose size is specified with a size clause
8212 Any packed array type with a static size
8216 For all these cases, if the component subtype size is in the range
8217 1 through 63, then the effect of the pragma @code{Pack} is exactly as though a
8218 component size were specified giving the component subtype size.
8219 For example if we have:
8222 type r is range 0 .. 17;
8224 type ar is array (1 .. 8) of r;
8229 Then the component size of @code{ar} will be set to 5 (i.e.@: to @code{r'size},
8230 and the size of the array @code{ar} will be exactly 40 bits.
8232 Note that in some cases this rather fierce approach to packing can produce
8233 unexpected effects. For example, in Ada 95, type Natural typically has a
8234 size of 31, meaning that if you pack an array of Natural, you get 31-bit
8235 close packing, which saves a few bits, but results in far less efficient
8236 access. Since many other Ada compilers will ignore such a packing request,
8237 GNAT will generate a warning on some uses of pragma @code{Pack} that it guesses
8238 might not be what is intended. You can easily remove this warning by
8239 using an explicit @code{Component_Size} setting instead, which never generates
8240 a warning, since the intention of the programmer is clear in this case.
8242 GNAT treats packed arrays in one of two ways. If the size of the array is
8243 known at compile time and is less than 64 bits, then internally the array
8244 is represented as a single modular type, of exactly the appropriate number
8245 of bits. If the length is greater than 63 bits, or is not known at compile
8246 time, then the packed array is represented as an array of bytes, and the
8247 length is always a multiple of 8 bits.
8249 @node Pragma Pack for Records
8250 @section Pragma Pack for Records
8251 @cindex Pragma Pack (for records)
8254 Pragma @code{Pack} applied to a record will pack the components to reduce wasted
8255 space from alignment gaps and by reducing the amount of space taken by
8256 components. We distinguish between package components and non-packable
8257 components. Components of the following types are considered packable:
8261 All scalar types are packable.
8264 All fixed-point types are represented internally as integers, and
8268 Small packed arrays, whose size does not exceed 64 bits, and where the
8269 size is statically known at compile time, are represented internally
8270 as modular integers, and so they are also packable.
8275 All packable components occupy the exact number of bits corresponding to
8276 their @code{Size} value, and are packed with no padding bits, i.e.@: they
8277 can start on an arbitrary bit boundary.
8279 All other types are non-packable, they occupy an integral number of
8281 are placed at a boundary corresponding to their alignment requirements.
8283 For example, consider the record
8286 type Rb1 is array (1 .. 13) of Boolean;
8289 type Rb2 is array (1 .. 65) of Boolean;
8304 The representation for the record x2 is as follows:
8307 for x2'Size use 224;
8309 l1 at 0 range 0 .. 0;
8310 l2 at 0 range 1 .. 64;
8311 l3 at 12 range 0 .. 31;
8312 l4 at 16 range 0 .. 0;
8313 l5 at 16 range 1 .. 13;
8314 l6 at 18 range 0 .. 71;
8319 Studying this example, we see that the packable fields @code{l1}
8321 of length equal to their sizes, and placed at specific bit boundaries (and
8322 not byte boundaries) to
8323 eliminate padding. But @code{l3} is of a non-packable float type, so
8324 it is on the next appropriate alignment boundary.
8326 The next two fields are fully packable, so @code{l4} and @code{l5} are
8327 minimally packed with no gaps. However, type @code{Rb2} is a packed
8328 array that is longer than 64 bits, so it is itself non-packable. Thus
8329 the @code{l6} field is aligned to the next byte boundary, and takes an
8330 integral number of bytes, i.e.@: 72 bits.
8332 @node Record Representation Clauses
8333 @section Record Representation Clauses
8334 @cindex Record Representation Clause
8337 Record representation clauses may be given for all record types, including
8338 types obtained by record extension. Component clauses are allowed for any
8339 static component. The restrictions on component clauses depend on the type
8342 @cindex Component Clause
8343 For all components of an elementary type, the only restriction on component
8344 clauses is that the size must be at least the 'Size value of the type
8345 (actually the Value_Size). There are no restrictions due to alignment,
8346 and such components may freely cross storage boundaries.
8348 Packed arrays with a size up to and including 64 bits are represented
8349 internally using a modular type with the appropriate number of bits, and
8350 thus the same lack of restriction applies. For example, if you declare:
8353 type R is array (1 .. 49) of Boolean;
8359 then a component clause for a component of type R may start on any
8360 specified bit boundary, and may specify a value of 49 bits or greater.
8362 For non-primitive types, including packed arrays with a size greater than
8363 64 bits, component clauses must respect the alignment requirement of the
8364 type, in particular, always starting on a byte boundary, and the length
8365 must be a multiple of the storage unit.
8367 The tag field of a tagged type always occupies an address sized field at
8368 the start of the record. No component clause may attempt to overlay this
8371 In the case of a record extension T1, of a type T, no component clause applied
8372 to the type T1 can specify a storage location that would overlap the first
8373 T'Size bytes of the record.
8375 @node Enumeration Clauses
8376 @section Enumeration Clauses
8378 The only restriction on enumeration clauses is that the range of values
8379 must be representable. For the signed case, if one or more of the
8380 representation values are negative, all values must be in the range:
8383 System.Min_Int .. System.Max_Int
8387 For the unsigned case, where all values are non negative, the values must
8391 0 .. System.Max_Binary_Modulus;
8395 A @emph{confirming} representation clause is one in which the values range
8396 from 0 in sequence, i.e.@: a clause that confirms the default representation
8397 for an enumeration type.
8398 Such a confirming representation
8399 is permitted by these rules, and is specially recognized by the compiler so
8400 that no extra overhead results from the use of such a clause.
8402 If an array has an index type which is an enumeration type to which an
8403 enumeration clause has been applied, then the array is stored in a compact
8404 manner. Consider the declarations:
8407 type r is (A, B, C);
8408 for r use (A => 1, B => 5, C => 10);
8409 type t is array (r) of Character;
8413 The array type t corresponds to a vector with exactly three elements and
8414 has a default size equal to @code{3*Character'Size}. This ensures efficient
8415 use of space, but means that accesses to elements of the array will incur
8416 the overhead of converting representation values to the corresponding
8417 positional values, (i.e.@: the value delivered by the @code{Pos} attribute).
8419 @node Address Clauses
8420 @section Address Clauses
8421 @cindex Address Clause
8423 The reference manual allows a general restriction on representation clauses,
8424 as found in RM 13.1(22):
8427 An implementation need not support representation
8428 items containing nonstatic expressions, except that
8429 an implementation should support a representation item
8430 for a given entity if each nonstatic expression in the
8431 representation item is a name that statically denotes
8432 a constant declared before the entity.
8436 In practice this is applicable only to address clauses, since this is the
8437 only case in which a non-static expression is permitted by the syntax. As
8438 the AARM notes in sections 13.1 (22.a-22.h):
8441 22.a Reason: This is to avoid the following sort
8444 22.b X : Integer := F(@dots{});
8445 Y : Address := G(@dots{});
8446 for X'Address use Y;
8448 22.c In the above, we have to evaluate the
8449 initialization expression for X before we
8450 know where to put the result. This seems
8451 like an unreasonable implementation burden.
8453 22.d The above code should instead be written
8456 22.e Y : constant Address := G(@dots{});
8457 X : Integer := F(@dots{});
8458 for X'Address use Y;
8460 22.f This allows the expression ``Y'' to be safely
8461 evaluated before X is created.
8463 22.g The constant could be a formal parameter of mode in.
8465 22.h An implementation can support other nonstatic
8466 expressions if it wants to. Expressions of type
8467 Address are hardly ever static, but their value
8468 might be known at compile time anyway in many
8473 GNAT does indeed permit many additional cases of non-static expressions. In
8474 particular, if the type involved is elementary there are no restrictions
8475 (since in this case, holding a temporary copy of the initialization value,
8476 if one is present, is inexpensive). In addition, if there is no implicit or
8477 explicit initialization, then there are no restrictions. GNAT will reject
8478 only the case where all three of these conditions hold:
8483 The type of the item is non-elementary (e.g.@: a record or array).
8486 There is explicit or implicit initialization required for the object.
8489 The address value is non-static. Here GNAT is more permissive than the
8490 RM, and allows the address value to be the address of a previously declared
8491 stand-alone variable, as long as it does not itself have an address clause.
8494 Anchor : Some_Initialized_Type;
8495 Overlay : Some_Initialized_Type;
8496 for Overlay'Address use Anchor'Address;
8499 However, the prefix of the address clause cannot be an array component, or
8500 a component of a discriminated record.
8505 As noted above in section 22.h, address values are typically non-static. In
8506 particular the To_Address function, even if applied to a literal value, is
8507 a non-static function call. To avoid this minor annoyance, GNAT provides
8508 the implementation defined attribute 'To_Address. The following two
8509 expressions have identical values:
8511 Another issue with address clauses is the interaction with alignment
8512 requirements. When an address clause is given for an object, the address
8513 value must be consistent with the alignment of the object (which is usually
8514 the same as the alignment of the type of the object). If an address clause
8515 is given that specifies an inappropriately aligned address value, then the
8516 program execution is erroneous.
8518 Since this source of erroneous behavior can have unfortunate effects, GNAT
8519 checks (at compile time if possible, generating a warning, or at execution
8520 time with a run-time check) that the alignment is appropriate. If the
8521 run-time check fails, then @code{Program_Error} is raised. This run-time
8522 check is suppressed if range checks are suppressed, or if
8523 @code{pragma Restrictions (No_Elaboration_Code)} is in effect.
8528 To_Address (16#1234_0000#)
8529 System'To_Address (16#1234_0000#);
8533 except that the second form is considered to be a static expression, and
8534 thus when used as an address clause value is always permitted.
8537 Additionally, GNAT treats as static an address clause that is an
8538 unchecked_conversion of a static integer value. This simplifies the porting
8539 of legacy code, and provides a portable equivalent to the GNAT attribute
8543 An address clause cannot be given for an exported object. More
8544 understandably the real restriction is that objects with an address
8545 clause cannot be exported. This is because such variables are not
8546 defined by the Ada program, so there is no external object so export.
8549 It is permissible to give an address clause and a pragma Import for the
8550 same object. In this case, the variable is not really defined by the
8551 Ada program, so there is no external symbol to be linked. The link name
8552 and the external name are ignored in this case. The reason that we allow this
8553 combination is that it provides a useful idiom to avoid unwanted
8554 initializations on objects with address clauses.
8556 When an address clause is given for an object that has implicit or
8557 explicit initialization, then by default initialization takes place. This
8558 means that the effect of the object declaration is to overwrite the
8559 memory at the specified address. This is almost always not what the
8560 programmer wants, so GNAT will output a warning:
8570 for Ext'Address use System'To_Address (16#1234_1234#);
8572 >>> warning: implicit initialization of "Ext" may
8573 modify overlaid storage
8574 >>> warning: use pragma Import for "Ext" to suppress
8575 initialization (RM B(24))
8581 As indicated by the warning message, the solution is to use a (dummy) pragma
8582 Import to suppress this initialization. The pragma tell the compiler that the
8583 object is declared and initialized elsewhere. The following package compiles
8584 without warnings (and the initialization is suppressed):
8594 for Ext'Address use System'To_Address (16#1234_1234#);
8595 pragma Import (Ada, Ext);
8599 @node Effect of Convention on Representation
8600 @section Effect of Convention on Representation
8601 @cindex Convention, effect on representation
8604 Normally the specification of a foreign language convention for a type or
8605 an object has no effect on the chosen representation. In particular, the
8606 representation chosen for data in GNAT generally meets the standard system
8607 conventions, and for example records are laid out in a manner that is
8608 consistent with C@. This means that specifying convention C (for example)
8611 There are three exceptions to this general rule:
8615 @item Convention Fortran and array subtypes
8616 If pragma Convention Fortran is specified for an array subtype, then in
8617 accordance with the implementation advice in section 3.6.2(11) of the
8618 Ada Reference Manual, the array will be stored in a Fortran-compatible
8619 column-major manner, instead of the normal default row-major order.
8621 @item Convention C and enumeration types
8622 GNAT normally stores enumeration types in 8, 16, or 32 bits as required
8623 to accommodate all values of the type. For example, for the enumeration
8627 type Color is (Red, Green, Blue);
8631 8 bits is sufficient to store all values of the type, so by default, objects
8632 of type @code{Color} will be represented using 8 bits. However, normal C
8633 convention is to use 32 bits for all enum values in C, since enum values
8634 are essentially of type int. If pragma @code{Convention C} is specified for an
8635 Ada enumeration type, then the size is modified as necessary (usually to
8636 32 bits) to be consistent with the C convention for enum values.
8638 @item Convention C/Fortran and Boolean types
8639 In C, the usual convention for boolean values, that is values used for
8640 conditions, is that zero represents false, and nonzero values represent
8641 true. In Ada, the normal convention is that two specific values, typically
8642 0/1, are used to represent false/true respectively.
8644 Fortran has a similar convention for @code{LOGICAL} values (any nonzero
8645 value represents true).
8647 To accommodate the Fortran and C conventions, if a pragma Convention specifies
8648 C or Fortran convention for a derived Boolean, as in the following example:
8651 type C_Switch is new Boolean;
8652 pragma Convention (C, C_Switch);
8656 then the GNAT generated code will treat any nonzero value as true. For truth
8657 values generated by GNAT, the conventional value 1 will be used for True, but
8658 when one of these values is read, any nonzero value is treated as True.
8662 @node Determining the Representations chosen by GNAT
8663 @section Determining the Representations chosen by GNAT
8664 @cindex Representation, determination of
8665 @cindex @code{-gnatR} switch
8668 Although the descriptions in this section are intended to be complete, it is
8669 often easier to simply experiment to see what GNAT accepts and what the
8670 effect is on the layout of types and objects.
8672 As required by the Ada RM, if a representation clause is not accepted, then
8673 it must be rejected as illegal by the compiler. However, when a representation
8674 clause or pragma is accepted, there can still be questions of what the
8675 compiler actually does. For example, if a partial record representation
8676 clause specifies the location of some components and not others, then where
8677 are the non-specified components placed? Or if pragma @code{Pack} is used on a
8678 record, then exactly where are the resulting fields placed? The section
8679 on pragma @code{Pack} in this chapter can be used to answer the second question,
8680 but it is often easier to just see what the compiler does.
8682 For this purpose, GNAT provides the option @code{-gnatR}. If you compile
8683 with this option, then the compiler will output information on the actual
8684 representations chosen, in a format similar to source representation
8685 clauses. For example, if we compile the package:
8689 type r (x : boolean) is tagged record
8691 when True => S : String (1 .. 100);
8696 type r2 is new r (false) with record
8701 y2 at 16 range 0 .. 31;
8708 type x1 is array (1 .. 10) of x;
8709 for x1'component_size use 11;
8711 type ia is access integer;
8713 type Rb1 is array (1 .. 13) of Boolean;
8716 type Rb2 is array (1 .. 65) of Boolean;
8732 using the switch @code{-gnatR} we obtain the following output:
8735 Representation information for unit q
8736 -------------------------------------
8739 for r'Alignment use 4;
8741 x at 4 range 0 .. 7;
8742 _tag at 0 range 0 .. 31;
8743 s at 5 range 0 .. 799;
8746 for r2'Size use 160;
8747 for r2'Alignment use 4;
8749 x at 4 range 0 .. 7;
8750 _tag at 0 range 0 .. 31;
8751 _parent at 0 range 0 .. 63;
8752 y2 at 16 range 0 .. 31;
8756 for x'Alignment use 1;
8758 y at 0 range 0 .. 7;
8761 for x1'Size use 112;
8762 for x1'Alignment use 1;
8763 for x1'Component_Size use 11;
8765 for rb1'Size use 13;
8766 for rb1'Alignment use 2;
8767 for rb1'Component_Size use 1;
8769 for rb2'Size use 72;
8770 for rb2'Alignment use 1;
8771 for rb2'Component_Size use 1;
8773 for x2'Size use 224;
8774 for x2'Alignment use 4;
8776 l1 at 0 range 0 .. 0;
8777 l2 at 0 range 1 .. 64;
8778 l3 at 12 range 0 .. 31;
8779 l4 at 16 range 0 .. 0;
8780 l5 at 16 range 1 .. 13;
8781 l6 at 18 range 0 .. 71;
8786 The Size values are actually the Object_Size, i.e.@: the default size that
8787 will be allocated for objects of the type.
8788 The ?? size for type r indicates that we have a variant record, and the
8789 actual size of objects will depend on the discriminant value.
8791 The Alignment values show the actual alignment chosen by the compiler
8792 for each record or array type.
8794 The record representation clause for type r shows where all fields
8795 are placed, including the compiler generated tag field (whose location
8796 cannot be controlled by the programmer).
8798 The record representation clause for the type extension r2 shows all the
8799 fields present, including the parent field, which is a copy of the fields
8800 of the parent type of r2, i.e.@: r1.
8802 The component size and size clauses for types rb1 and rb2 show
8803 the exact effect of pragma @code{Pack} on these arrays, and the record
8804 representation clause for type x2 shows how pragma @code{Pack} affects
8807 In some cases, it may be useful to cut and paste the representation clauses
8808 generated by the compiler into the original source to fix and guarantee
8809 the actual representation to be used.
8811 @node Standard Library Routines
8812 @chapter Standard Library Routines
8815 The Ada 95 Reference Manual contains in Annex A a full description of an
8816 extensive set of standard library routines that can be used in any Ada
8817 program, and which must be provided by all Ada compilers. They are
8818 analogous to the standard C library used by C programs.
8820 GNAT implements all of the facilities described in annex A, and for most
8821 purposes the description in the Ada 95
8822 reference manual, or appropriate Ada
8823 text book, will be sufficient for making use of these facilities.
8825 In the case of the input-output facilities, @xref{The Implementation of
8826 Standard I/O}, gives details on exactly how GNAT interfaces to the
8827 file system. For the remaining packages, the Ada 95 reference manual
8828 should be sufficient. The following is a list of the packages included,
8829 together with a brief description of the functionality that is provided.
8831 For completeness, references are included to other predefined library
8832 routines defined in other sections of the Ada 95 reference manual (these are
8833 cross-indexed from annex A).
8837 This is a parent package for all the standard library packages. It is
8838 usually included implicitly in your program, and itself contains no
8839 useful data or routines.
8841 @item Ada.Calendar (9.6)
8842 @code{Calendar} provides time of day access, and routines for
8843 manipulating times and durations.
8845 @item Ada.Characters (A.3.1)
8846 This is a dummy parent package that contains no useful entities
8848 @item Ada.Characters.Handling (A.3.2)
8849 This package provides some basic character handling capabilities,
8850 including classification functions for classes of characters (e.g.@: test
8851 for letters, or digits).
8853 @item Ada.Characters.Latin_1 (A.3.3)
8854 This package includes a complete set of definitions of the characters
8855 that appear in type CHARACTER@. It is useful for writing programs that
8856 will run in international environments. For example, if you want an
8857 upper case E with an acute accent in a string, it is often better to use
8858 the definition of @code{UC_E_Acute} in this package. Then your program
8859 will print in an understandable manner even if your environment does not
8860 support these extended characters.
8862 @item Ada.Command_Line (A.15)
8863 This package provides access to the command line parameters and the name
8864 of the current program (analogous to the use of @code{argc} and @code{argv} in C), and
8865 also allows the exit status for the program to be set in a
8866 system-independent manner.
8868 @item Ada.Decimal (F.2)
8869 This package provides constants describing the range of decimal numbers
8870 implemented, and also a decimal divide routine (analogous to the COBOL
8871 verb DIVIDE .. GIVING .. REMAINDER ..)
8873 @item Ada.Direct_IO (A.8.4)
8874 This package provides input-output using a model of a set of records of
8875 fixed-length, containing an arbitrary definite Ada type, indexed by an
8876 integer record number.
8878 @item Ada.Dynamic_Priorities (D.5)
8879 This package allows the priorities of a task to be adjusted dynamically
8880 as the task is running.
8882 @item Ada.Exceptions (11.4.1)
8883 This package provides additional information on exceptions, and also
8884 contains facilities for treating exceptions as data objects, and raising
8885 exceptions with associated messages.
8887 @item Ada.Finalization (7.6)
8888 This package contains the declarations and subprograms to support the
8889 use of controlled types, providing for automatic initialization and
8890 finalization (analogous to the constructors and destructors of C++)
8892 @item Ada.Interrupts (C.3.2)
8893 This package provides facilities for interfacing to interrupts, which
8894 includes the set of signals or conditions that can be raised and
8895 recognized as interrupts.
8897 @item Ada.Interrupts.Names (C.3.2)
8898 This package provides the set of interrupt names (actually signal
8899 or condition names) that can be handled by GNAT@.
8901 @item Ada.IO_Exceptions (A.13)
8902 This package defines the set of exceptions that can be raised by use of
8903 the standard IO packages.
8906 This package contains some standard constants and exceptions used
8907 throughout the numerics packages. Note that the constants pi and e are
8908 defined here, and it is better to use these definitions than rolling
8911 @item Ada.Numerics.Complex_Elementary_Functions
8912 Provides the implementation of standard elementary functions (such as
8913 log and trigonometric functions) operating on complex numbers using the
8914 standard @code{Float} and the @code{Complex} and @code{Imaginary} types
8915 created by the package @code{Numerics.Complex_Types}.
8917 @item Ada.Numerics.Complex_Types
8918 This is a predefined instantiation of
8919 @code{Numerics.Generic_Complex_Types} using @code{Standard.Float} to
8920 build the type @code{Complex} and @code{Imaginary}.
8922 @item Ada.Numerics.Discrete_Random
8923 This package provides a random number generator suitable for generating
8924 random integer values from a specified range.
8926 @item Ada.Numerics.Float_Random
8927 This package provides a random number generator suitable for generating
8928 uniformly distributed floating point values.
8930 @item Ada.Numerics.Generic_Complex_Elementary_Functions
8931 This is a generic version of the package that provides the
8932 implementation of standard elementary functions (such as log and
8933 trigonometric functions) for an arbitrary complex type.
8935 The following predefined instantiations of this package are provided:
8939 @code{Ada.Numerics.Short_Complex_Elementary_Functions}
8941 @code{Ada.Numerics.Complex_Elementary_Functions}
8944 Long_Complex_Elementary_Functions}
8947 @item Ada.Numerics.Generic_Complex_Types
8948 This is a generic package that allows the creation of complex types,
8949 with associated complex arithmetic operations.
8951 The following predefined instantiations of this package exist
8954 @code{Ada.Numerics.Short_Complex_Complex_Types}
8956 @code{Ada.Numerics.Complex_Complex_Types}
8958 @code{Ada.Numerics.Long_Complex_Complex_Types}
8961 @item Ada.Numerics.Generic_Elementary_Functions
8962 This is a generic package that provides the implementation of standard
8963 elementary functions (such as log an trigonometric functions) for an
8964 arbitrary float type.
8966 The following predefined instantiations of this package exist
8970 @code{Ada.Numerics.Short_Elementary_Functions}
8972 @code{Ada.Numerics.Elementary_Functions}
8974 @code{Ada.Numerics.Long_Elementary_Functions}
8977 @item Ada.Real_Time (D.8)
8978 This package provides facilities similar to those of @code{Calendar}, but
8979 operating with a finer clock suitable for real time control. Note that
8980 annex D requires that there be no backward clock jumps, and GNAT generally
8981 guarantees this behavior, but of course if the external clock on which
8982 the GNAT runtime depends is deliberately reset by some external event,
8983 then such a backward jump may occur.
8985 @item Ada.Sequential_IO (A.8.1)
8986 This package provides input-output facilities for sequential files,
8987 which can contain a sequence of values of a single type, which can be
8988 any Ada type, including indefinite (unconstrained) types.
8990 @item Ada.Storage_IO (A.9)
8991 This package provides a facility for mapping arbitrary Ada types to and
8992 from a storage buffer. It is primarily intended for the creation of new
8995 @item Ada.Streams (13.13.1)
8996 This is a generic package that provides the basic support for the
8997 concept of streams as used by the stream attributes (@code{Input},
8998 @code{Output}, @code{Read} and @code{Write}).
9000 @item Ada.Streams.Stream_IO (A.12.1)
9001 This package is a specialization of the type @code{Streams} defined in
9002 package @code{Streams} together with a set of operations providing
9003 Stream_IO capability. The Stream_IO model permits both random and
9004 sequential access to a file which can contain an arbitrary set of values
9005 of one or more Ada types.
9007 @item Ada.Strings (A.4.1)
9008 This package provides some basic constants used by the string handling
9011 @item Ada.Strings.Bounded (A.4.4)
9012 This package provides facilities for handling variable length
9013 strings. The bounded model requires a maximum length. It is thus
9014 somewhat more limited than the unbounded model, but avoids the use of
9015 dynamic allocation or finalization.
9017 @item Ada.Strings.Fixed (A.4.3)
9018 This package provides facilities for handling fixed length strings.
9020 @item Ada.Strings.Maps (A.4.2)
9021 This package provides facilities for handling character mappings and
9022 arbitrarily defined subsets of characters. For instance it is useful in
9023 defining specialized translation tables.
9025 @item Ada.Strings.Maps.Constants (A.4.6)
9026 This package provides a standard set of predefined mappings and
9027 predefined character sets. For example, the standard upper to lower case
9028 conversion table is found in this package. Note that upper to lower case
9029 conversion is non-trivial if you want to take the entire set of
9030 characters, including extended characters like E with an acute accent,
9031 into account. You should use the mappings in this package (rather than
9032 adding 32 yourself) to do case mappings.
9034 @item Ada.Strings.Unbounded (A.4.5)
9035 This package provides facilities for handling variable length
9036 strings. The unbounded model allows arbitrary length strings, but
9037 requires the use of dynamic allocation and finalization.
9039 @item Ada.Strings.Wide_Bounded (A.4.7)
9040 @itemx Ada.Strings.Wide_Fixed (A.4.7)
9041 @itemx Ada.Strings.Wide_Maps (A.4.7)
9042 @itemx Ada.Strings.Wide_Maps.Constants (A.4.7)
9043 @itemx Ada.Strings.Wide_Unbounded (A.4.7)
9044 These package provide analogous capabilities to the corresponding
9045 packages without @samp{Wide_} in the name, but operate with the types
9046 @code{Wide_String} and @code{Wide_Character} instead of @code{String}
9047 and @code{Character}.
9049 @item Ada.Synchronous_Task_Control (D.10)
9050 This package provides some standard facilities for controlling task
9051 communication in a synchronous manner.
9054 This package contains definitions for manipulation of the tags of tagged
9057 @item Ada.Task_Attributes
9058 This package provides the capability of associating arbitrary
9059 task-specific data with separate tasks.
9062 This package provides basic text input-output capabilities for
9063 character, string and numeric data. The subpackages of this
9064 package are listed next.
9066 @item Ada.Text_IO.Decimal_IO
9067 Provides input-output facilities for decimal fixed-point types
9069 @item Ada.Text_IO.Enumeration_IO
9070 Provides input-output facilities for enumeration types.
9072 @item Ada.Text_IO.Fixed_IO
9073 Provides input-output facilities for ordinary fixed-point types.
9075 @item Ada.Text_IO.Float_IO
9076 Provides input-output facilities for float types. The following
9077 predefined instantiations of this generic package are available:
9081 @code{Short_Float_Text_IO}
9083 @code{Float_Text_IO}
9085 @code{Long_Float_Text_IO}
9088 @item Ada.Text_IO.Integer_IO
9089 Provides input-output facilities for integer types. The following
9090 predefined instantiations of this generic package are available:
9093 @item Short_Short_Integer
9094 @code{Ada.Short_Short_Integer_Text_IO}
9096 @code{Ada.Short_Integer_Text_IO}
9098 @code{Ada.Integer_Text_IO}
9100 @code{Ada.Long_Integer_Text_IO}
9101 @item Long_Long_Integer
9102 @code{Ada.Long_Long_Integer_Text_IO}
9105 @item Ada.Text_IO.Modular_IO
9106 Provides input-output facilities for modular (unsigned) types
9108 @item Ada.Text_IO.Complex_IO (G.1.3)
9109 This package provides basic text input-output capabilities for complex
9112 @item Ada.Text_IO.Editing (F.3.3)
9113 This package contains routines for edited output, analogous to the use
9114 of pictures in COBOL@. The picture formats used by this package are a
9115 close copy of the facility in COBOL@.
9117 @item Ada.Text_IO.Text_Streams (A.12.2)
9118 This package provides a facility that allows Text_IO files to be treated
9119 as streams, so that the stream attributes can be used for writing
9120 arbitrary data, including binary data, to Text_IO files.
9122 @item Ada.Unchecked_Conversion (13.9)
9123 This generic package allows arbitrary conversion from one type to
9124 another of the same size, providing for breaking the type safety in
9125 special circumstances.
9127 If the types have the same Size (more accurately the same Value_Size),
9128 then the effect is simply to transfer the bits from the source to the
9129 target type without any modification. This usage is well defined, and
9130 for simple types whose representation is typically the same across
9131 all implementations, gives a portable method of performing such
9134 If the types do not have the same size, then the result is implementation
9135 defined, and thus may be non-portable. The following describes how GNAT
9136 handles such unchecked conversion cases.
9138 If the types are of different sizes, and are both discrete types, then
9139 the effect is of a normal type conversion without any constraint checking.
9140 In particular if the result type has a larger size, the result will be
9141 zero or sign extended. If the result type has a smaller size, the result
9142 will be truncated by ignoring high order bits.
9144 If the types are of different sizes, and are not both discrete types,
9145 then the conversion works as though pointers were created to the source
9146 and target, and the pointer value is converted. The effect is that bits
9147 are copied from successive low order storage units and bits of the source
9148 up to the length of the target type.
9150 A warning is issued if the lengths differ, since the effect in this
9151 case is implementation dependent, and the above behavior may not match
9152 that of some other compiler.
9154 A pointer to one type may be converted to a pointer to another type using
9155 unchecked conversion. The only case in which the effect is undefined is
9156 when one or both pointers are pointers to unconstrained array types. In
9157 this case, the bounds information may get incorrectly transferred, and in
9158 particular, GNAT uses double size pointers for such types, and it is
9159 meaningless to convert between such pointer types. GNAT will issue a
9160 warning if the alignment of the target designated type is more strict
9161 than the alignment of the source designated type (since the result may
9162 be unaligned in this case).
9164 A pointer other than a pointer to an unconstrained array type may be
9165 converted to and from System.Address. Such usage is common in Ada 83
9166 programs, but note that Ada.Address_To_Access_Conversions is the
9167 preferred method of performing such conversions in Ada 95. Neither
9168 unchecked conversion nor Ada.Address_To_Access_Conversions should be
9169 used in conjunction with pointers to unconstrained objects, since
9170 the bounds information cannot be handled correctly in this case.
9172 @item Ada.Unchecked_Deallocation (13.11.2)
9173 This generic package allows explicit freeing of storage previously
9174 allocated by use of an allocator.
9176 @item Ada.Wide_Text_IO (A.11)
9177 This package is similar to @code{Ada.Text_IO}, except that the external
9178 file supports wide character representations, and the internal types are
9179 @code{Wide_Character} and @code{Wide_String} instead of @code{Character}
9180 and @code{String}. It contains generic subpackages listed next.
9182 @item Ada.Wide_Text_IO.Decimal_IO
9183 Provides input-output facilities for decimal fixed-point types
9185 @item Ada.Wide_Text_IO.Enumeration_IO
9186 Provides input-output facilities for enumeration types.
9188 @item Ada.Wide_Text_IO.Fixed_IO
9189 Provides input-output facilities for ordinary fixed-point types.
9191 @item Ada.Wide_Text_IO.Float_IO
9192 Provides input-output facilities for float types. The following
9193 predefined instantiations of this generic package are available:
9197 @code{Short_Float_Wide_Text_IO}
9199 @code{Float_Wide_Text_IO}
9201 @code{Long_Float_Wide_Text_IO}
9204 @item Ada.Wide_Text_IO.Integer_IO
9205 Provides input-output facilities for integer types. The following
9206 predefined instantiations of this generic package are available:
9209 @item Short_Short_Integer
9210 @code{Ada.Short_Short_Integer_Wide_Text_IO}
9212 @code{Ada.Short_Integer_Wide_Text_IO}
9214 @code{Ada.Integer_Wide_Text_IO}
9216 @code{Ada.Long_Integer_Wide_Text_IO}
9217 @item Long_Long_Integer
9218 @code{Ada.Long_Long_Integer_Wide_Text_IO}
9221 @item Ada.Wide_Text_IO.Modular_IO
9222 Provides input-output facilities for modular (unsigned) types
9224 @item Ada.Wide_Text_IO.Complex_IO (G.1.3)
9225 This package is similar to @code{Ada.Text_IO.Complex_IO}, except that the
9226 external file supports wide character representations.
9228 @item Ada.Wide_Text_IO.Editing (F.3.4)
9229 This package is similar to @code{Ada.Text_IO.Editing}, except that the
9230 types are @code{Wide_Character} and @code{Wide_String} instead of
9231 @code{Character} and @code{String}.
9233 @item Ada.Wide_Text_IO.Streams (A.12.3)
9234 This package is similar to @code{Ada.Text_IO.Streams}, except that the
9235 types are @code{Wide_Character} and @code{Wide_String} instead of
9236 @code{Character} and @code{String}.
9238 @node The Implementation of Standard I/O
9239 @chapter The Implementation of Standard I/O
9242 GNAT implements all the required input-output facilities described in
9243 A.6 through A.14. These sections of the Ada 95 reference manual describe the
9244 required behavior of these packages from the Ada point of view, and if
9245 you are writing a portable Ada program that does not need to know the
9246 exact manner in which Ada maps to the outside world when it comes to
9247 reading or writing external files, then you do not need to read this
9248 chapter. As long as your files are all regular files (not pipes or
9249 devices), and as long as you write and read the files only from Ada, the
9250 description in the Ada 95 reference manual is sufficient.
9252 However, if you want to do input-output to pipes or other devices, such
9253 as the keyboard or screen, or if the files you are dealing with are
9254 either generated by some other language, or to be read by some other
9255 language, then you need to know more about the details of how the GNAT
9256 implementation of these input-output facilities behaves.
9258 In this chapter we give a detailed description of exactly how GNAT
9259 interfaces to the file system. As always, the sources of the system are
9260 available to you for answering questions at an even more detailed level,
9261 but for most purposes the information in this chapter will suffice.
9263 Another reason that you may need to know more about how input-output is
9264 implemented arises when you have a program written in mixed languages
9265 where, for example, files are shared between the C and Ada sections of
9266 the same program. GNAT provides some additional facilities, in the form
9267 of additional child library packages, that facilitate this sharing, and
9268 these additional facilities are also described in this chapter.
9271 * Standard I/O Packages::
9280 * Operations on C Streams::
9281 * Interfacing to C Streams::
9284 @node Standard I/O Packages
9285 @section Standard I/O Packages
9288 The Standard I/O packages described in Annex A for
9294 Ada.Text_IO.Complex_IO
9296 Ada.Text_IO.Text_Streams,
9300 Ada.Wide_Text_IO.Complex_IO,
9302 Ada.Wide_Text_IO.Text_Streams
9312 are implemented using the C
9313 library streams facility; where
9317 All files are opened using @code{fopen}.
9319 All input/output operations use @code{fread}/@code{fwrite}.
9322 There is no internal buffering of any kind at the Ada library level. The
9323 only buffering is that provided at the system level in the
9324 implementation of the C library routines that support streams. This
9325 facilitates shared use of these streams by mixed language programs.
9328 @section FORM Strings
9331 The format of a FORM string in GNAT is:
9334 "keyword=value,keyword=value,@dots{},keyword=value"
9338 where letters may be in upper or lower case, and there are no spaces
9339 between values. The order of the entries is not important. Currently
9340 there are two keywords defined.
9347 The use of these parameters is described later in this section.
9353 Direct_IO can only be instantiated for definite types. This is a
9354 restriction of the Ada language, which means that the records are fixed
9355 length (the length being determined by @code{@var{type}'Size}, rounded
9356 up to the next storage unit boundary if necessary).
9358 The records of a Direct_IO file are simply written to the file in index
9359 sequence, with the first record starting at offset zero, and subsequent
9360 records following. There is no control information of any kind. For
9361 example, if 32-bit integers are being written, each record takes
9362 4-bytes, so the record at index @var{K} starts at offset
9363 (@var{K}@minus{}1)*4.
9365 There is no limit on the size of Direct_IO files, they are expanded as
9366 necessary to accommodate whatever records are written to the file.
9369 @section Sequential_IO
9372 Sequential_IO may be instantiated with either a definite (constrained)
9373 or indefinite (unconstrained) type.
9375 For the definite type case, the elements written to the file are simply
9376 the memory images of the data values with no control information of any
9377 kind. The resulting file should be read using the same type, no validity
9378 checking is performed on input.
9380 For the indefinite type case, the elements written consist of two
9381 parts. First is the size of the data item, written as the memory image
9382 of a @code{Interfaces.C.size_t} value, followed by the memory image of
9383 the data value. The resulting file can only be read using the same
9384 (unconstrained) type. Normal assignment checks are performed on these
9385 read operations, and if these checks fail, @code{Data_Error} is
9386 raised. In particular, in the array case, the lengths must match, and in
9387 the variant record case, if the variable for a particular read operation
9388 is constrained, the discriminants must match.
9390 Note that it is not possible to use Sequential_IO to write variable
9391 length array items, and then read the data back into different length
9392 arrays. For example, the following will raise @code{Data_Error}:
9395 package IO is new Sequential_IO (String);
9400 IO.Write (F, "hello!")
9401 IO.Reset (F, Mode=>In_File);
9407 On some Ada implementations, this will print @samp{hell}, but the program is
9408 clearly incorrect, since there is only one element in the file, and that
9409 element is the string @samp{hello!}.
9411 In Ada 95, this kind of behavior can be legitimately achieved using
9412 Stream_IO, and this is the preferred mechanism. In particular, the above
9413 program fragment rewritten to use Stream_IO will work correctly.
9419 Text_IO files consist of a stream of characters containing the following
9420 special control characters:
9423 LF (line feed, 16#0A#) Line Mark
9424 FF (form feed, 16#0C#) Page Mark
9427 A canonical Text_IO file is defined as one in which the following
9432 The character @code{LF} is used only as a line mark, i.e.@: to mark the end
9436 The character @code{FF} is used only as a page mark, i.e.@: to mark the
9437 end of a page and consequently can appear only immediately following a
9438 @code{LF} (line mark) character.
9441 The file ends with either @code{LF} (line mark) or @code{LF}-@code{FF}
9442 (line mark, page mark). In the former case, the page mark is implicitly
9443 assumed to be present.
9446 A file written using Text_IO will be in canonical form provided that no
9447 explicit @code{LF} or @code{FF} characters are written using @code{Put}
9448 or @code{Put_Line}. There will be no @code{FF} character at the end of
9449 the file unless an explicit @code{New_Page} operation was performed
9450 before closing the file.
9452 A canonical Text_IO file that is a regular file, i.e.@: not a device or a
9453 pipe, can be read using any of the routines in Text_IO@. The
9454 semantics in this case will be exactly as defined in the Ada 95 reference
9455 manual and all the routines in Text_IO are fully implemented.
9457 A text file that does not meet the requirements for a canonical Text_IO
9458 file has one of the following:
9462 The file contains @code{FF} characters not immediately following a
9463 @code{LF} character.
9466 The file contains @code{LF} or @code{FF} characters written by
9467 @code{Put} or @code{Put_Line}, which are not logically considered to be
9468 line marks or page marks.
9471 The file ends in a character other than @code{LF} or @code{FF},
9472 i.e.@: there is no explicit line mark or page mark at the end of the file.
9475 Text_IO can be used to read such non-standard text files but subprograms
9476 to do with line or page numbers do not have defined meanings. In
9477 particular, a @code{FF} character that does not follow a @code{LF}
9478 character may or may not be treated as a page mark from the point of
9479 view of page and line numbering. Every @code{LF} character is considered
9480 to end a line, and there is an implied @code{LF} character at the end of
9484 * Text_IO Stream Pointer Positioning::
9485 * Text_IO Reading and Writing Non-Regular Files::
9487 * Treating Text_IO Files as Streams::
9488 * Text_IO Extensions::
9489 * Text_IO Facilities for Unbounded Strings::
9491 @node Text_IO Stream Pointer Positioning
9493 @subsection Stream Pointer Positioning
9496 @code{Ada.Text_IO} has a definition of current position for a file that
9497 is being read. No internal buffering occurs in Text_IO, and usually the
9498 physical position in the stream used to implement the file corresponds
9499 to this logical position defined by Text_IO@. There are two exceptions:
9503 After a call to @code{End_Of_Page} that returns @code{True}, the stream
9504 is positioned past the @code{LF} (line mark) that precedes the page
9505 mark. Text_IO maintains an internal flag so that subsequent read
9506 operations properly handle the logical position which is unchanged by
9507 the @code{End_Of_Page} call.
9510 After a call to @code{End_Of_File} that returns @code{True}, if the
9511 Text_IO file was positioned before the line mark at the end of file
9512 before the call, then the logical position is unchanged, but the stream
9513 is physically positioned right at the end of file (past the line mark,
9514 and past a possible page mark following the line mark. Again Text_IO
9515 maintains internal flags so that subsequent read operations properly
9516 handle the logical position.
9519 These discrepancies have no effect on the observable behavior of
9520 Text_IO, but if a single Ada stream is shared between a C program and
9521 Ada program, or shared (using @samp{shared=yes} in the form string)
9522 between two Ada files, then the difference may be observable in some
9525 @node Text_IO Reading and Writing Non-Regular Files
9526 @subsection Reading and Writing Non-Regular Files
9529 A non-regular file is a device (such as a keyboard), or a pipe. Text_IO
9530 can be used for reading and writing. Writing is not affected and the
9531 sequence of characters output is identical to the normal file case, but
9532 for reading, the behavior of Text_IO is modified to avoid undesirable
9533 look-ahead as follows:
9535 An input file that is not a regular file is considered to have no page
9536 marks. Any @code{Ascii.FF} characters (the character normally used for a
9537 page mark) appearing in the file are considered to be data
9538 characters. In particular:
9542 @code{Get_Line} and @code{Skip_Line} do not test for a page mark
9543 following a line mark. If a page mark appears, it will be treated as a
9547 This avoids the need to wait for an extra character to be typed or
9548 entered from the pipe to complete one of these operations.
9551 @code{End_Of_Page} always returns @code{False}
9554 @code{End_Of_File} will return @code{False} if there is a page mark at
9555 the end of the file.
9558 Output to non-regular files is the same as for regular files. Page marks
9559 may be written to non-regular files using @code{New_Page}, but as noted
9560 above they will not be treated as page marks on input if the output is
9561 piped to another Ada program.
9563 Another important discrepancy when reading non-regular files is that the end
9564 of file indication is not ``sticky''. If an end of file is entered, e.g.@: by
9565 pressing the @key{EOT} key,
9567 is signalled once (i.e.@: the test @code{End_Of_File}
9568 will yield @code{True}, or a read will
9569 raise @code{End_Error}), but then reading can resume
9570 to read data past that end of
9571 file indication, until another end of file indication is entered.
9574 @subsection Get_Immediate
9575 @cindex Get_Immediate
9578 Get_Immediate returns the next character (including control characters)
9579 from the input file. In particular, Get_Immediate will return LF or FF
9580 characters used as line marks or page marks. Such operations leave the
9581 file positioned past the control character, and it is thus not treated
9582 as having its normal function. This means that page, line and column
9583 counts after this kind of Get_Immediate call are set as though the mark
9584 did not occur. In the case where a Get_Immediate leaves the file
9585 positioned between the line mark and page mark (which is not normally
9586 possible), it is undefined whether the FF character will be treated as a
9589 @node Treating Text_IO Files as Streams
9590 @subsection Treating Text_IO Files as Streams
9591 @cindex Stream files
9594 The package @code{Text_IO.Streams} allows a Text_IO file to be treated
9595 as a stream. Data written to a Text_IO file in this stream mode is
9596 binary data. If this binary data contains bytes 16#0A# (@code{LF}) or
9597 16#0C# (@code{FF}), the resulting file may have non-standard
9598 format. Similarly if read operations are used to read from a Text_IO
9599 file treated as a stream, then @code{LF} and @code{FF} characters may be
9600 skipped and the effect is similar to that described above for
9601 @code{Get_Immediate}.
9603 @node Text_IO Extensions
9604 @subsection Text_IO Extensions
9605 @cindex Text_IO extensions
9608 A package GNAT.IO_Aux in the GNAT library provides some useful extensions
9609 to the standard @code{Text_IO} package:
9612 @item function File_Exists (Name : String) return Boolean;
9613 Determines if a file of the given name exists and can be successfully
9614 opened (without actually performing the open operation).
9616 @item function Get_Line return String;
9617 Reads a string from the standard input file. The value returned is exactly
9618 the length of the line that was read.
9620 @item function Get_Line (File : Ada.Text_IO.File_Type) return String;
9621 Similar, except that the parameter File specifies the file from which
9622 the string is to be read.
9626 @node Text_IO Facilities for Unbounded Strings
9627 @subsection Text_IO Facilities for Unbounded Strings
9628 @cindex Text_IO for unbounded strings
9629 @cindex Unbounded_String, Text_IO operations
9632 The package @code{Ada.Strings.Unbounded.Text_IO}
9633 in library files @code{a-suteio.ads/adb} contains some GNAT-specific
9634 subprograms useful for Text_IO operations on unbounded strings:
9638 @item function Get_Line (File : File_Type) return Unbounded_String;
9639 Reads a line from the specified file
9640 and returns the result as an unbounded string.
9642 @item procedure Put (File : File_Type; U : Unbounded_String);
9643 Writes the value of the given unbounded string to the specified file
9644 Similar to the effect of
9645 @code{Put (To_String (U))} except that an extra copy is avoided.
9647 @item procedure Put_Line (File : File_Type; U : Unbounded_String);
9648 Writes the value of the given unbounded string to the specified file,
9649 followed by a @code{New_Line}.
9650 Similar to the effect of @code{Put_Line (To_String (U))} except
9651 that an extra copy is avoided.
9655 In the above procedures, @code{File} is of type @code{Ada.Text_IO.File_Type}
9656 and is optional. If the parameter is omitted, then the standard input or
9657 output file is referenced as appropriate.
9659 The package @code{Ada.Strings.Wide_Unbounded.Wide_Text_IO} in library
9660 files @file{a-swuwti.ads} and @file{a-swuwti.adb} provides similar extended @code{Wide_Text_IO}
9661 functionality for unbounded wide strings.
9664 @section Wide_Text_IO
9667 @code{Wide_Text_IO} is similar in most respects to Text_IO, except that
9668 both input and output files may contain special sequences that represent
9669 wide character values. The encoding scheme for a given file may be
9670 specified using a FORM parameter:
9677 as part of the FORM string (WCEM = wide character encoding method),
9678 where @var{x} is one of the following characters
9695 The encoding methods match those that
9696 can be used in a source
9697 program, but there is no requirement that the encoding method used for
9698 the source program be the same as the encoding method used for files,
9699 and different files may use different encoding methods.
9701 The default encoding method for the standard files, and for opened files
9702 for which no WCEM parameter is given in the FORM string matches the
9703 wide character encoding specified for the main program (the default
9704 being brackets encoding if no coding method was specified with -gnatW).
9708 In this encoding, a wide character is represented by a five character
9715 where @var{a}, @var{b}, @var{c}, @var{d} are the four hexadecimal
9716 characters (using upper case letters) of the wide character code. For
9717 example, ESC A345 is used to represent the wide character with code
9718 16#A345#. This scheme is compatible with use of the full
9719 @code{Wide_Character} set.
9721 @item Upper Half Coding
9722 The wide character with encoding 16#abcd#, where the upper bit is on
9723 (i.e.@: a is in the range 8-F) is represented as two bytes 16#ab# and
9724 16#cd#. The second byte may never be a format control character, but is
9725 not required to be in the upper half. This method can be also used for
9726 shift-JIS or EUC where the internal coding matches the external coding.
9728 @item Shift JIS Coding
9729 A wide character is represented by a two character sequence 16#ab# and
9730 16#cd#, with the restrictions described for upper half encoding as
9731 described above. The internal character code is the corresponding JIS
9732 character according to the standard algorithm for Shift-JIS
9733 conversion. Only characters defined in the JIS code set table can be
9734 used with this encoding method.
9737 A wide character is represented by a two character sequence 16#ab# and
9738 16#cd#, with both characters being in the upper half. The internal
9739 character code is the corresponding JIS character according to the EUC
9740 encoding algorithm. Only characters defined in the JIS code set table
9741 can be used with this encoding method.
9744 A wide character is represented using
9745 UCS Transformation Format 8 (UTF-8) as defined in Annex R of ISO
9746 10646-1/Am.2. Depending on the character value, the representation
9747 is a one, two, or three byte sequence:
9750 16#0000#-16#007f#: 2#0xxxxxxx#
9751 16#0080#-16#07ff#: 2#110xxxxx# 2#10xxxxxx#
9752 16#0800#-16#ffff#: 2#1110xxxx# 2#10xxxxxx# 2#10xxxxxx#
9755 where the xxx bits correspond to the left-padded bits of the
9756 16-bit character value. Note that all lower half ASCII characters
9757 are represented as ASCII bytes and all upper half characters and
9758 other wide characters are represented as sequences of upper-half
9759 (The full UTF-8 scheme allows for encoding 31-bit characters as
9760 6-byte sequences, but in this implementation, all UTF-8 sequences
9761 of four or more bytes length will raise a Constraint_Error, as
9762 will all invalid UTF-8 sequences.)
9764 @item Brackets Coding
9765 In this encoding, a wide character is represented by the following eight
9772 Where @code{a}, @code{b}, @code{c}, @code{d} are the four hexadecimal
9773 characters (using uppercase letters) of the wide character code. For
9774 example, @code{["A345"]} is used to represent the wide character with code
9776 This scheme is compatible with use of the full Wide_Character set.
9777 On input, brackets coding can also be used for upper half characters,
9778 e.g.@: @code{["C1"]} for lower case a. However, on output, brackets notation
9779 is only used for wide characters with a code greater than @code{16#FF#}.
9783 For the coding schemes other than Hex and Brackets encoding,
9784 not all wide character
9785 values can be represented. An attempt to output a character that cannot
9786 be represented using the encoding scheme for the file causes
9787 Constraint_Error to be raised. An invalid wide character sequence on
9788 input also causes Constraint_Error to be raised.
9791 * Wide_Text_IO Stream Pointer Positioning::
9792 * Wide_Text_IO Reading and Writing Non-Regular Files::
9795 @node Wide_Text_IO Stream Pointer Positioning
9796 @subsection Stream Pointer Positioning
9799 @code{Ada.Wide_Text_IO} is similar to @code{Ada.Text_IO} in its handling
9800 of stream pointer positioning (@pxref{Text_IO}). There is one additional
9803 If @code{Ada.Wide_Text_IO.Look_Ahead} reads a character outside the
9804 normal lower ASCII set (i.e.@: a character in the range:
9807 Wide_Character'Val (16#0080#) .. Wide_Character'Val (16#FFFF#)
9811 then although the logical position of the file pointer is unchanged by
9812 the @code{Look_Ahead} call, the stream is physically positioned past the
9813 wide character sequence. Again this is to avoid the need for buffering
9814 or backup, and all @code{Wide_Text_IO} routines check the internal
9815 indication that this situation has occurred so that this is not visible
9816 to a normal program using @code{Wide_Text_IO}. However, this discrepancy
9817 can be observed if the wide text file shares a stream with another file.
9819 @node Wide_Text_IO Reading and Writing Non-Regular Files
9820 @subsection Reading and Writing Non-Regular Files
9823 As in the case of Text_IO, when a non-regular file is read, it is
9824 assumed that the file contains no page marks (any form characters are
9825 treated as data characters), and @code{End_Of_Page} always returns
9826 @code{False}. Similarly, the end of file indication is not sticky, so
9827 it is possible to read beyond an end of file.
9833 A stream file is a sequence of bytes, where individual elements are
9834 written to the file as described in the Ada 95 reference manual. The type
9835 @code{Stream_Element} is simply a byte. There are two ways to read or
9836 write a stream file.
9840 The operations @code{Read} and @code{Write} directly read or write a
9841 sequence of stream elements with no control information.
9844 The stream attributes applied to a stream file transfer data in the
9845 manner described for stream attributes.
9849 @section Shared Files
9852 Section A.14 of the Ada 95 Reference Manual allows implementations to
9853 provide a wide variety of behavior if an attempt is made to access the
9854 same external file with two or more internal files.
9856 To provide a full range of functionality, while at the same time
9857 minimizing the problems of portability caused by this implementation
9858 dependence, GNAT handles file sharing as follows:
9862 In the absence of a @samp{shared=@var{xxx}} form parameter, an attempt
9863 to open two or more files with the same full name is considered an error
9864 and is not supported. The exception @code{Use_Error} will be
9865 raised. Note that a file that is not explicitly closed by the program
9866 remains open until the program terminates.
9869 If the form parameter @samp{shared=no} appears in the form string, the
9870 file can be opened or created with its own separate stream identifier,
9871 regardless of whether other files sharing the same external file are
9872 opened. The exact effect depends on how the C stream routines handle
9873 multiple accesses to the same external files using separate streams.
9876 If the form parameter @samp{shared=yes} appears in the form string for
9877 each of two or more files opened using the same full name, the same
9878 stream is shared between these files, and the semantics are as described
9879 in Ada 95 Reference Manual, Section A.14.
9882 When a program that opens multiple files with the same name is ported
9883 from another Ada compiler to GNAT, the effect will be that
9884 @code{Use_Error} is raised.
9886 The documentation of the original compiler and the documentation of the
9887 program should then be examined to determine if file sharing was
9888 expected, and @samp{shared=@var{xxx}} parameters added to @code{Open}
9889 and @code{Create} calls as required.
9891 When a program is ported from GNAT to some other Ada compiler, no
9892 special attention is required unless the @samp{shared=@var{xxx}} form
9893 parameter is used in the program. In this case, you must examine the
9894 documentation of the new compiler to see if it supports the required
9895 file sharing semantics, and form strings modified appropriately. Of
9896 course it may be the case that the program cannot be ported if the
9897 target compiler does not support the required functionality. The best
9898 approach in writing portable code is to avoid file sharing (and hence
9899 the use of the @samp{shared=@var{xxx}} parameter in the form string)
9902 One common use of file sharing in Ada 83 is the use of instantiations of
9903 Sequential_IO on the same file with different types, to achieve
9904 heterogeneous input-output. Although this approach will work in GNAT if
9905 @samp{shared=yes} is specified, it is preferable in Ada 95 to use Stream_IO
9906 for this purpose (using the stream attributes)
9912 @code{Open} and @code{Create} calls result in a call to @code{fopen}
9913 using the mode shown in Table 6.1
9916 @center Table 6-1 @code{Open} and @code{Create} Call Modes
9918 @b{OPEN } @b{CREATE}
9919 Append_File "r+" "w+"
9921 Out_File (Direct_IO) "r+" "w"
9922 Out_File (all other cases) "w" "w"
9923 Inout_File "r+" "w+"
9926 If text file translation is required, then either @samp{b} or @samp{t}
9927 is added to the mode, depending on the setting of Text. Text file
9928 translation refers to the mapping of CR/LF sequences in an external file
9929 to LF characters internally. This mapping only occurs in DOS and
9930 DOS-like systems, and is not relevant to other systems.
9932 A special case occurs with Stream_IO@. As shown in the above table, the
9933 file is initially opened in @samp{r} or @samp{w} mode for the
9934 @code{In_File} and @code{Out_File} cases. If a @code{Set_Mode} operation
9935 subsequently requires switching from reading to writing or vice-versa,
9936 then the file is reopened in @samp{r+} mode to permit the required operation.
9938 @node Operations on C Streams
9939 @section Operations on C Streams
9940 The package @code{Interfaces.C_Streams} provides an Ada program with direct
9941 access to the C library functions for operations on C streams:
9944 package Interfaces.C_Streams is
9945 -- Note: the reason we do not use the types that are in
9946 -- Interfaces.C is that we want to avoid dragging in the
9947 -- code in this unit if possible.
9948 subtype chars is System.Address;
9949 -- Pointer to null-terminated array of characters
9950 subtype FILEs is System.Address;
9951 -- Corresponds to the C type FILE*
9952 subtype voids is System.Address;
9953 -- Corresponds to the C type void*
9954 subtype int is Integer;
9955 subtype long is Long_Integer;
9956 -- Note: the above types are subtypes deliberately, and it
9957 -- is part of this spec that the above correspondences are
9958 -- guaranteed. This means that it is legitimate to, for
9959 -- example, use Integer instead of int. We provide these
9960 -- synonyms for clarity, but in some cases it may be
9961 -- convenient to use the underlying types (for example to
9962 -- avoid an unnecessary dependency of a spec on the spec
9964 type size_t is mod 2 ** Standard'Address_Size;
9965 NULL_Stream : constant FILEs;
9966 -- Value returned (NULL in C) to indicate an
9967 -- fdopen/fopen/tmpfile error
9968 ----------------------------------
9969 -- Constants Defined in stdio.h --
9970 ----------------------------------
9972 -- Used by a number of routines to indicate error or
9974 IOFBF : constant int;
9975 IOLBF : constant int;
9976 IONBF : constant int;
9977 -- Used to indicate buffering mode for setvbuf call
9978 SEEK_CUR : constant int;
9979 SEEK_END : constant int;
9980 SEEK_SET : constant int;
9981 -- Used to indicate origin for fseek call
9982 function stdin return FILEs;
9983 function stdout return FILEs;
9984 function stderr return FILEs;
9985 -- Streams associated with standard files
9986 --------------------------
9987 -- Standard C functions --
9988 --------------------------
9989 -- The functions selected below are ones that are
9990 -- available in DOS, OS/2, UNIX and Xenix (but not
9991 -- necessarily in ANSI C). These are very thin interfaces
9992 -- which copy exactly the C headers. For more
9993 -- documentation on these functions, see the Microsoft C
9994 -- "Run-Time Library Reference" (Microsoft Press, 1990,
9995 -- ISBN 1-55615-225-6), which includes useful information
9996 -- on system compatibility.
9997 procedure clearerr (stream : FILEs);
9998 function fclose (stream : FILEs) return int;
9999 function fdopen (handle : int; mode : chars) return FILEs;
10000 function feof (stream : FILEs) return int;
10001 function ferror (stream : FILEs) return int;
10002 function fflush (stream : FILEs) return int;
10003 function fgetc (stream : FILEs) return int;
10004 function fgets (strng : chars; n : int; stream : FILEs)
10006 function fileno (stream : FILEs) return int;
10007 function fopen (filename : chars; Mode : chars)
10009 -- Note: to maintain target independence, use
10010 -- text_translation_required, a boolean variable defined in
10011 -- a-sysdep.c to deal with the target dependent text
10012 -- translation requirement. If this variable is set,
10013 -- then b/t should be appended to the standard mode
10014 -- argument to set the text translation mode off or on
10016 function fputc (C : int; stream : FILEs) return int;
10017 function fputs (Strng : chars; Stream : FILEs) return int;
10034 function ftell (stream : FILEs) return long;
10041 function isatty (handle : int) return int;
10042 procedure mktemp (template : chars);
10043 -- The return value (which is just a pointer to template)
10045 procedure rewind (stream : FILEs);
10046 function rmtmp return int;
10054 function tmpfile return FILEs;
10055 function ungetc (c : int; stream : FILEs) return int;
10056 function unlink (filename : chars) return int;
10057 ---------------------
10058 -- Extra functions --
10059 ---------------------
10060 -- These functions supply slightly thicker bindings than
10061 -- those above. They are derived from functions in the
10062 -- C Run-Time Library, but may do a bit more work than
10063 -- just directly calling one of the Library functions.
10064 function is_regular_file (handle : int) return int;
10065 -- Tests if given handle is for a regular file (result 1)
10066 -- or for a non-regular file (pipe or device, result 0).
10067 ---------------------------------
10068 -- Control of Text/Binary Mode --
10069 ---------------------------------
10070 -- If text_translation_required is true, then the following
10071 -- functions may be used to dynamically switch a file from
10072 -- binary to text mode or vice versa. These functions have
10073 -- no effect if text_translation_required is false (i.e. in
10074 -- normal UNIX mode). Use fileno to get a stream handle.
10075 procedure set_binary_mode (handle : int);
10076 procedure set_text_mode (handle : int);
10077 ----------------------------
10078 -- Full Path Name support --
10079 ----------------------------
10080 procedure full_name (nam : chars; buffer : chars);
10081 -- Given a NUL terminated string representing a file
10082 -- name, returns in buffer a NUL terminated string
10083 -- representing the full path name for the file name.
10084 -- On systems where it is relevant the drive is also
10085 -- part of the full path name. It is the responsibility
10086 -- of the caller to pass an actual parameter for buffer
10087 -- that is big enough for any full path name. Use
10088 -- max_path_len given below as the size of buffer.
10089 max_path_len : integer;
10090 -- Maximum length of an allowable full path name on the
10091 -- system, including a terminating NUL character.
10092 end Interfaces.C_Streams;
10095 @node Interfacing to C Streams
10096 @section Interfacing to C Streams
10099 The packages in this section permit interfacing Ada files to C Stream
10103 with Interfaces.C_Streams;
10104 package Ada.Sequential_IO.C_Streams is
10105 function C_Stream (F : File_Type)
10106 return Interfaces.C_Streams.FILEs;
10108 (File : in out File_Type;
10109 Mode : in File_Mode;
10110 C_Stream : in Interfaces.C_Streams.FILEs;
10111 Form : in String := "");
10112 end Ada.Sequential_IO.C_Streams;
10114 with Interfaces.C_Streams;
10115 package Ada.Direct_IO.C_Streams is
10116 function C_Stream (F : File_Type)
10117 return Interfaces.C_Streams.FILEs;
10119 (File : in out File_Type;
10120 Mode : in File_Mode;
10121 C_Stream : in Interfaces.C_Streams.FILEs;
10122 Form : in String := "");
10123 end Ada.Direct_IO.C_Streams;
10125 with Interfaces.C_Streams;
10126 package Ada.Text_IO.C_Streams is
10127 function C_Stream (F : File_Type)
10128 return Interfaces.C_Streams.FILEs;
10130 (File : in out File_Type;
10131 Mode : in File_Mode;
10132 C_Stream : in Interfaces.C_Streams.FILEs;
10133 Form : in String := "");
10134 end Ada.Text_IO.C_Streams;
10136 with Interfaces.C_Streams;
10137 package Ada.Wide_Text_IO.C_Streams is
10138 function C_Stream (F : File_Type)
10139 return Interfaces.C_Streams.FILEs;
10141 (File : in out File_Type;
10142 Mode : in File_Mode;
10143 C_Stream : in Interfaces.C_Streams.FILEs;
10144 Form : in String := "");
10145 end Ada.Wide_Text_IO.C_Streams;
10147 with Interfaces.C_Streams;
10148 package Ada.Stream_IO.C_Streams is
10149 function C_Stream (F : File_Type)
10150 return Interfaces.C_Streams.FILEs;
10152 (File : in out File_Type;
10153 Mode : in File_Mode;
10154 C_Stream : in Interfaces.C_Streams.FILEs;
10155 Form : in String := "");
10156 end Ada.Stream_IO.C_Streams;
10159 In each of these five packages, the @code{C_Stream} function obtains the
10160 @code{FILE} pointer from a currently opened Ada file. It is then
10161 possible to use the @code{Interfaces.C_Streams} package to operate on
10162 this stream, or the stream can be passed to a C program which can
10163 operate on it directly. Of course the program is responsible for
10164 ensuring that only appropriate sequences of operations are executed.
10166 One particular use of relevance to an Ada program is that the
10167 @code{setvbuf} function can be used to control the buffering of the
10168 stream used by an Ada file. In the absence of such a call the standard
10169 default buffering is used.
10171 The @code{Open} procedures in these packages open a file giving an
10172 existing C Stream instead of a file name. Typically this stream is
10173 imported from a C program, allowing an Ada file to operate on an
10176 @node The GNAT Library
10177 @chapter The GNAT Library
10180 The GNAT library contains a number of general and special purpose packages.
10181 It represents functionality that the GNAT developers have found useful, and
10182 which is made available to GNAT users. The packages described here are fully
10183 supported, and upwards compatibility will be maintained in future releases,
10184 so you can use these facilities with the confidence that the same functionality
10185 will be available in future releases.
10187 The chapter here simply gives a brief summary of the facilities available.
10188 The full documentation is found in the spec file for the package. The full
10189 sources of these library packages, including both spec and body, are provided
10190 with all GNAT releases. For example, to find out the full specifications of
10191 the SPITBOL pattern matching capability, including a full tutorial and
10192 extensive examples, look in the @file{g-spipat.ads} file in the library.
10194 For each entry here, the package name (as it would appear in a @code{with}
10195 clause) is given, followed by the name of the corresponding spec file in
10196 parentheses. The packages are children in four hierarchies, @code{Ada},
10197 @code{Interfaces}, @code{System}, and @code{GNAT}, the latter being a
10198 GNAT-specific hierarchy.
10200 Note that an application program should only use packages in one of these
10201 four hierarchies if the package is defined in the Ada Reference Manual,
10202 or is listed in this section of the GNAT Programmers Reference Manual.
10203 All other units should be considered internal implementation units and
10204 should not be directly @code{with}'ed by application code. The use of
10205 a @code{with} statement that references one of these internal implementation
10206 units makes an application potentially dependent on changes in versions
10207 of GNAT, and will generate a warning message.
10210 * Ada.Characters.Latin_9 (a-chlat9.ads)::
10211 * Ada.Characters.Wide_Latin_1 (a-cwila1.ads)::
10212 * Ada.Characters.Wide_Latin_9 (a-cwila9.ads)::
10213 * Ada.Command_Line.Remove (a-colire.ads)::
10214 * Ada.Direct_IO.C_Streams (a-diocst.ads)::
10215 * Ada.Exceptions.Is_Null_Occurrence (a-einuoc.ads)::
10216 * Ada.Sequential_IO.C_Streams (a-siocst.ads)::
10217 * Ada.Streams.Stream_IO.C_Streams (a-ssicst.ads)::
10218 * Ada.Strings.Unbounded.Text_IO (a-suteio.ads)::
10219 * Ada.Strings.Wide_Unbounded.Wide_Text_IO (a-swuwti.ads)::
10220 * Ada.Text_IO.C_Streams (a-tiocst.ads)::
10221 * Ada.Wide_Text_IO.C_Streams (a-wtcstr.ads)::
10222 * GNAT.AWK (g-awk.ads)::
10223 * GNAT.Bubble_Sort_A (g-busora.ads)::
10224 * GNAT.Bubble_Sort_G (g-busorg.ads)::
10225 * GNAT.Calendar (g-calend.ads)::
10226 * GNAT.Calendar.Time_IO (g-catiio.ads)::
10227 * GNAT.CRC32 (g-crc32.ads)::
10228 * GNAT.Case_Util (g-casuti.ads)::
10229 * GNAT.CGI (g-cgi.ads)::
10230 * GNAT.CGI.Cookie (g-cgicoo.ads)::
10231 * GNAT.CGI.Debug (g-cgideb.ads)::
10232 * GNAT.Command_Line (g-comlin.ads)::
10233 * GNAT.Current_Exception (g-curexc.ads)::
10234 * GNAT.Debug_Pools (g-debpoo.ads)::
10235 * GNAT.Debug_Utilities (g-debuti.ads)::
10236 * GNAT.Directory_Operations (g-dirope.ads)::
10237 * GNAT.Dynamic_Tables (g-dyntab.ads)::
10238 * GNAT.Exception_Traces (g-exctra.ads)::
10239 * GNAT.Expect (g-expect.ads)::
10240 * GNAT.Float_Control (g-flocon.ads)::
10241 * GNAT.Heap_Sort_A (g-hesora.ads)::
10242 * GNAT.Heap_Sort_G (g-hesorg.ads)::
10243 * GNAT.HTable (g-htable.ads)::
10244 * GNAT.IO (g-io.ads)::
10245 * GNAT.IO_Aux (g-io_aux.ads)::
10246 * GNAT.Lock_Files (g-locfil.ads)::
10247 * GNAT.MD5 (g-md5.ads)::
10248 * GNAT.Most_Recent_Exception (g-moreex.ads)::
10249 * GNAT.OS_Lib (g-os_lib.ads)::
10250 * GNAT.Regexp (g-regexp.ads)::
10251 * GNAT.Registry (g-regist.ads)::
10252 * GNAT.Regpat (g-regpat.ads)::
10253 * GNAT.Sockets (g-socket.ads)::
10254 * GNAT.Source_Info (g-souinf.ads)::
10255 * GNAT.Spell_Checker (g-speche.ads)::
10256 * GNAT.Spitbol.Patterns (g-spipat.ads)::
10257 * GNAT.Spitbol (g-spitbo.ads)::
10258 * GNAT.Spitbol.Table_Boolean (g-sptabo.ads)::
10259 * GNAT.Spitbol.Table_Integer (g-sptain.ads)::
10260 * GNAT.Spitbol.Table_VString (g-sptavs.ads)::
10261 * GNAT.Table (g-table.ads)::
10262 * GNAT.Task_Lock (g-tasloc.ads)::
10263 * GNAT.Threads (g-thread.ads)::
10264 * GNAT.Traceback (g-traceb.ads)::
10265 * GNAT.Traceback.Symbolic (g-trasym.ads)::
10266 * Interfaces.C.Extensions (i-cexten.ads)::
10267 * Interfaces.C.Streams (i-cstrea.ads)::
10268 * Interfaces.CPP (i-cpp.ads)::
10269 * Interfaces.Os2lib (i-os2lib.ads)::
10270 * Interfaces.Os2lib.Errors (i-os2err.ads)::
10271 * Interfaces.Os2lib.Synchronization (i-os2syn.ads)::
10272 * Interfaces.Os2lib.Threads (i-os2thr.ads)::
10273 * Interfaces.Packed_Decimal (i-pacdec.ads)::
10274 * Interfaces.VxWorks (i-vxwork.ads)::
10275 * Interfaces.VxWorks.IO (i-vxwoio.ads)::
10276 * System.Address_Image (s-addima.ads)::
10277 * System.Assertions (s-assert.ads)::
10278 * System.Partition_Interface (s-parint.ads)::
10279 * System.Task_Info (s-tasinf.ads)::
10280 * System.Wch_Cnv (s-wchcnv.ads)::
10281 * System.Wch_Con (s-wchcon.ads)::
10284 @node Ada.Characters.Latin_9 (a-chlat9.ads)
10285 @section @code{Ada.Characters.Latin_9} (@file{a-chlat9.ads})
10286 @cindex @code{Ada.Characters.Latin_9} (@file{a-chlat9.ads})
10287 @cindex Latin_9 constants for Character
10290 This child of @code{Ada.Characters}
10291 provides a set of definitions corresponding to those in the
10292 RM-defined package @code{Ada.Characters.Latin_1} but with the
10293 few modifications required for @code{Latin-9}
10294 The provision of such a package
10295 is specifically authorized by the Ada Reference Manual
10298 @node Ada.Characters.Wide_Latin_1 (a-cwila1.ads)
10299 @section @code{Ada.Characters.Wide_Latin_1} (@file{a-cwila1.ads})
10300 @cindex @code{Ada.Characters.Wide_Latin_1} (@file{a-cwila1.ads})
10301 @cindex Latin_1 constants for Wide_Character
10304 This child of @code{Ada.Characters}
10305 provides a set of definitions corresponding to those in the
10306 RM-defined package @code{Ada.Characters.Latin_1} but with the
10307 types of the constants being @code{Wide_Character}
10308 instead of @code{Character}. The provision of such a package
10309 is specifically authorized by the Ada Reference Manual
10312 @node Ada.Characters.Wide_Latin_9 (a-cwila9.ads)
10313 @section @code{Ada.Characters.Wide_Latin_9} (@file{a-cwila1.ads})
10314 @cindex @code{Ada.Characters.Wide_Latin_9} (@file{a-cwila1.ads})
10315 @cindex Latin_9 constants for Wide_Character
10318 This child of @code{Ada.Characters}
10319 provides a set of definitions corresponding to those in the
10320 GNAT defined package @code{Ada.Characters.Latin_9} but with the
10321 types of the constants being @code{Wide_Character}
10322 instead of @code{Character}. The provision of such a package
10323 is specifically authorized by the Ada Reference Manual
10326 @node Ada.Command_Line.Remove (a-colire.ads)
10327 @section @code{Ada.Command_Line.Remove} (@file{a-colire.ads})
10328 @cindex @code{Ada.Command_Line.Remove} (@file{a-colire.ads})
10329 @cindex Removing command line arguments
10330 @cindex Command line, argument removal
10333 This child of @code{Ada.Command_Line}
10334 provides a mechanism for logically removing
10335 arguments from the argument list. Once removed, an argument is not visible
10336 to further calls on the subprograms in @code{Ada.Command_Line} will not
10337 see the removed argument.
10339 @node Ada.Direct_IO.C_Streams (a-diocst.ads)
10340 @section @code{Ada.Direct_IO.C_Streams} (@file{a-diocst.ads})
10341 @cindex @code{Ada.Direct_IO.C_Streams} (@file{a-diocst.ads})
10342 @cindex C Streams, Interfacing with Direct_IO
10345 This package provides subprograms that allow interfacing between
10346 C streams and @code{Direct_IO}. The stream identifier can be
10347 extracted from a file opened on the Ada side, and an Ada file
10348 can be constructed from a stream opened on the C side.
10350 @node Ada.Exceptions.Is_Null_Occurrence (a-einuoc.ads)
10351 @section @code{Ada.Exceptions.Is_Null_Occurrence} (@file{a-einuoc.ads})
10352 @cindex @code{Ada.Exceptions.Is_Null_Occurrence} (@file{a-einuoc.ads})
10353 @cindex Null_Occurrence, testing for
10356 This child subprogram provides a way of testing for the null
10357 exception occurrence (@code{Null_Occurrence}) without raising
10360 @node Ada.Sequential_IO.C_Streams (a-siocst.ads)
10361 @section @code{Ada.Sequential_IO.C_Streams} (@file{a-siocst.ads})
10362 @cindex @code{Ada.Sequential_IO.C_Streams} (@file{a-siocst.ads})
10363 @cindex C Streams, Interfacing with Sequential_IO
10366 This package provides subprograms that allow interfacing between
10367 C streams and @code{Sequential_IO}. The stream identifier can be
10368 extracted from a file opened on the Ada side, and an Ada file
10369 can be constructed from a stream opened on the C side.
10371 @node Ada.Streams.Stream_IO.C_Streams (a-ssicst.ads)
10372 @section @code{Ada.Streams.Stream_IO.C_Streams} (@file{a-ssicst.ads})
10373 @cindex @code{Ada.Streams.Stream_IO.C_Streams} (@file{a-ssicst.ads})
10374 @cindex C Streams, Interfacing with Stream_IO
10377 This package provides subprograms that allow interfacing between
10378 C streams and @code{Stream_IO}. The stream identifier can be
10379 extracted from a file opened on the Ada side, and an Ada file
10380 can be constructed from a stream opened on the C side.
10382 @node Ada.Strings.Unbounded.Text_IO (a-suteio.ads)
10383 @section @code{Ada.Strings.Unbounded.Text_IO} (@file{a-suteio.ads})
10384 @cindex @code{Ada.Strings.Unbounded.Text_IO} (@file{a-suteio.ads})
10385 @cindex @code{Unbounded_String}, IO support
10386 @cindex @code{Text_IO}, extensions for unbounded strings
10389 This package provides subprograms for Text_IO for unbounded
10390 strings, avoiding the necessity for an intermediate operation
10391 with ordinary strings.
10393 @node Ada.Strings.Wide_Unbounded.Wide_Text_IO (a-swuwti.ads)
10394 @section @code{Ada.Strings.Wide_Unbounded.Wide_Text_IO} (@file{a-swuwti.ads})
10395 @cindex @code{Ada.Strings.Wide_Unbounded.Wide_Text_IO} (@file{a-swuwti.ads})
10396 @cindex @code{Unbounded_Wide_String}, IO support
10397 @cindex @code{Text_IO}, extensions for unbounded wide strings
10400 This package provides subprograms for Text_IO for unbounded
10401 wide strings, avoiding the necessity for an intermediate operation
10402 with ordinary wide strings.
10404 @node Ada.Text_IO.C_Streams (a-tiocst.ads)
10405 @section @code{Ada.Text_IO.C_Streams} (@file{a-tiocst.ads})
10406 @cindex @code{Ada.Text_IO.C_Streams} (@file{a-tiocst.ads})
10407 @cindex C Streams, Interfacing with @code{Text_IO}
10410 This package provides subprograms that allow interfacing between
10411 C streams and @code{Text_IO}. The stream identifier can be
10412 extracted from a file opened on the Ada side, and an Ada file
10413 can be constructed from a stream opened on the C side.
10415 @node Ada.Wide_Text_IO.C_Streams (a-wtcstr.ads)
10416 @section @code{Ada.Wide_Text_IO.C_Streams} (@file{a-wtcstr.ads})
10417 @cindex @code{Ada.Wide_Text_IO.C_Streams} (@file{a-wtcstr.ads})
10418 @cindex C Streams, Interfacing with @code{Wide_Text_IO}
10421 This package provides subprograms that allow interfacing between
10422 C streams and @code{Wide_Text_IO}. The stream identifier can be
10423 extracted from a file opened on the Ada side, and an Ada file
10424 can be constructed from a stream opened on the C side.
10426 @node GNAT.AWK (g-awk.ads)
10427 @section @code{GNAT.AWK} (@file{g-awk.ads})
10428 @cindex @code{GNAT.AWK} (@file{g-awk.ads})
10433 Provides AWK-like parsing functions, with an easy interface for parsing one
10434 or more files containing formatted data. The file is viewed as a database
10435 where each record is a line and a field is a data element in this line.
10437 @node GNAT.Bubble_Sort_A (g-busora.ads)
10438 @section @code{GNAT.Bubble_Sort_A} (@file{g-busora.ads})
10439 @cindex @code{GNAT.Bubble_Sort_A} (@file{g-busora.ads})
10441 @cindex Bubble sort
10444 Provides a general implementation of bubble sort usable for sorting arbitrary
10445 data items. Move and comparison procedures are provided by passing
10446 access-to-procedure values.
10448 @node GNAT.Bubble_Sort_G (g-busorg.ads)
10449 @section @code{GNAT.Bubble_Sort_G} (@file{g-busorg.ads})
10450 @cindex @code{GNAT.Bubble_Sort_G} (@file{g-busorg.ads})
10452 @cindex Bubble sort
10455 Similar to @code{Bubble_Sort_A} except that the move and sorting procedures
10456 are provided as generic parameters, this improves efficiency, especially
10457 if the procedures can be inlined, at the expense of duplicating code for
10458 multiple instantiations.
10460 @node GNAT.Calendar (g-calend.ads)
10461 @section @code{GNAT.Calendar} (@file{g-calend.ads})
10462 @cindex @code{GNAT.Calendar} (@file{g-calend.ads})
10463 @cindex @code{Calendar}
10466 Extends the facilities provided by @code{Ada.Calendar} to include handling
10467 of days of the week, an extended @code{Split} and @code{Time_Of} capability.
10468 Also provides conversion of @code{Ada.Calendar.Time} values to and from the
10469 C @code{timeval} format.
10471 @node GNAT.Calendar.Time_IO (g-catiio.ads)
10472 @section @code{GNAT.Calendar.Time_IO} (@file{g-catiio.ads})
10473 @cindex @code{Calendar}
10475 @cindex @code{GNAT.Calendar.Time_IO} (@file{g-catiio.ads})
10477 @node GNAT.CRC32 (g-crc32.ads)
10478 @section @code{GNAT.CRC32} (@file{g-crc32.ads})
10479 @cindex @code{GNAT.CRC32} (@file{g-crc32.ads})
10481 @cindex Cyclic Redundancy Check
10484 This package implements the CRC-32 algorithm. For a full description
10485 of this algorithm you should have a look at:
10486 ``Computation of Cyclic Redundancy Checks via Table Look-Up'', @cite{Communications
10487 of the ACM}, Vol.@: 31 No.@: 8, pp.@: 1008-1013, Aug.@: 1988. Sarwate, D.V@.
10490 Provides an extended capability for formatted output of time values with
10491 full user control over the format. Modeled on the GNU Date specification.
10493 @node GNAT.Case_Util (g-casuti.ads)
10494 @section @code{GNAT.Case_Util} (@file{g-casuti.ads})
10495 @cindex @code{GNAT.Case_Util} (@file{g-casuti.ads})
10496 @cindex Casing utilities
10497 @cindex Character handling (@code{GNAT.Case_Util})
10500 A set of simple routines for handling upper and lower casing of strings
10501 without the overhead of the full casing tables
10502 in @code{Ada.Characters.Handling}.
10504 @node GNAT.CGI (g-cgi.ads)
10505 @section @code{GNAT.CGI} (@file{g-cgi.ads})
10506 @cindex @code{GNAT.CGI} (@file{g-cgi.ads})
10507 @cindex CGI (Common Gateway Interface)
10510 This is a package for interfacing a GNAT program with a Web server via the
10511 Common Gateway Interface (CGI)@. Basically this package parses the CGI
10512 parameters, which are a set of key/value pairs sent by the Web server. It
10513 builds a table whose index is the key and provides some services to deal
10516 @node GNAT.CGI.Cookie (g-cgicoo.ads)
10517 @section @code{GNAT.CGI.Cookie} (@file{g-cgicoo.ads})
10518 @cindex @code{GNAT.CGI.Cookie} (@file{g-cgicoo.ads})
10519 @cindex CGI (Common Gateway Interface) cookie support
10520 @cindex Cookie support in CGI
10523 This is a package to interface a GNAT program with a Web server via the
10524 Common Gateway Interface (CGI). It exports services to deal with Web
10525 cookies (piece of information kept in the Web client software).
10527 @node GNAT.CGI.Debug (g-cgideb.ads)
10528 @section @code{GNAT.CGI.Debug} (@file{g-cgideb.ads})
10529 @cindex @code{GNAT.CGI.Debug} (@file{g-cgideb.ads})
10530 @cindex CGI (Common Gateway Interface) debugging
10533 This is a package to help debugging CGI (Common Gateway Interface)
10534 programs written in Ada.
10536 @node GNAT.Command_Line (g-comlin.ads)
10537 @section @code{GNAT.Command_Line} (@file{g-comlin.ads})
10538 @cindex @code{GNAT.Command_Line} (@file{g-comlin.ads})
10539 @cindex Command line
10542 Provides a high level interface to @code{Ada.Command_Line} facilities,
10543 including the ability to scan for named switches with optional parameters
10544 and expand file names using wild card notations.
10546 @node GNAT.Current_Exception (g-curexc.ads)
10547 @section @code{GNAT.Current_Exception} (@file{g-curexc.ads})
10548 @cindex @code{GNAT.Current_Exception} (@file{g-curexc.ads})
10549 @cindex Current exception
10550 @cindex Exception retrieval
10553 Provides access to information on the current exception that has been raised
10554 without the need for using the Ada-95 exception choice parameter specification
10555 syntax. This is particularly useful in simulating typical facilities for
10556 obtaining information about exceptions provided by Ada 83 compilers.
10558 @node GNAT.Debug_Pools (g-debpoo.ads)
10559 @section @code{GNAT.Debug_Pools} (@file{g-debpoo.ads})
10560 @cindex @code{GNAT.Debug_Pools} (@file{g-debpoo.ads})
10562 @cindex Debug pools
10563 @cindex Memory corruption debugging
10566 Provide a debugging storage pools that helps tracking memory corruption
10567 problems. See section ``Finding memory problems with GNAT Debug Pool'' in
10568 the @cite{GNAT User's Guide}.
10570 @node GNAT.Debug_Utilities (g-debuti.ads)
10571 @section @code{GNAT.Debug_Utilities} (@file{g-debuti.ads})
10572 @cindex @code{GNAT.Debug_Utilities} (@file{g-debuti.ads})
10576 Provides a few useful utilities for debugging purposes, including conversion
10577 to and from string images of address values.
10579 @node GNAT.Directory_Operations (g-dirope.ads)
10580 @section @code{GNAT.Directory_Operations} (g-dirope.ads)
10581 @cindex @code{GNAT.Directory_Operations} (g-dirope.ads)
10582 @cindex Directory operations
10585 Provides a set of routines for manipulating directories, including changing
10586 the current directory, making new directories, and scanning the files in a
10589 @node GNAT.Dynamic_Tables (g-dyntab.ads)
10590 @section @code{GNAT.Dynamic_Tables} (@file{g-dyntab.ads})
10591 @cindex @code{GNAT.Dynamic_Tables} (@file{g-dyntab.ads})
10592 @cindex Table implementation
10593 @cindex Arrays, extendable
10596 A generic package providing a single dimension array abstraction where the
10597 length of the array can be dynamically modified.
10600 This package provides a facility similar to that of GNAT.Table, except
10601 that this package declares a type that can be used to define dynamic
10602 instances of the table, while an instantiation of GNAT.Table creates a
10603 single instance of the table type.
10605 @node GNAT.Exception_Traces (g-exctra.ads)
10606 @section @code{GNAT.Exception_Traces} (@file{g-exctra.ads})
10607 @cindex @code{GNAT.Exception_Traces} (@file{g-exctra.ads})
10608 @cindex Exception traces
10612 Provides an interface allowing to control automatic output upon exception
10615 @node GNAT.Expect (g-expect.ads)
10616 @section @code{GNAT.Expect} (@file{g-expect.ads})
10617 @cindex @code{GNAT.Expect} (@file{g-expect.ads})
10620 Provides a set of subprograms similar to what is available
10621 with the standard Tcl Expect tool.
10622 It allows you to easily spawn and communicate with an external process.
10623 You can send commands or inputs to the process, and compare the output
10624 with some expected regular expression.
10625 Currently GNAT.Expect is implemented on all native GNAT ports except for
10626 OpenVMS@. It is not implemented for cross ports, and in particular is not
10627 implemented for VxWorks or LynxOS@.
10629 @node GNAT.Float_Control (g-flocon.ads)
10630 @section @code{GNAT.Float_Control} (@file{g-flocon.ads})
10631 @cindex @code{GNAT.Float_Control} (@file{g-flocon.ads})
10632 @cindex Floating-Point Processor
10635 Provides an interface for resetting the floating-point processor into the
10636 mode required for correct semantic operation in Ada. Some third party
10637 library calls may cause this mode to be modified, and the Reset procedure
10638 in this package can be used to reestablish the required mode.
10640 @node GNAT.Heap_Sort_A (g-hesora.ads)
10641 @section @code{GNAT.Heap_Sort_A} (@file{g-hesora.ads})
10642 @cindex @code{GNAT.Heap_Sort_A} (@file{g-hesora.ads})
10646 Provides a general implementation of heap sort usable for sorting arbitrary
10647 data items. Move and comparison procedures are provided by passing
10648 access-to-procedure values. The algorithm used is a modified heap sort
10649 that performs approximately N*log(N) comparisons in the worst case.
10651 @node GNAT.Heap_Sort_G (g-hesorg.ads)
10652 @section @code{GNAT.Heap_Sort_G} (@file{g-hesorg.ads})
10653 @cindex @code{GNAT.Heap_Sort_G} (@file{g-hesorg.ads})
10657 Similar to @code{Heap_Sort_A} except that the move and sorting procedures
10658 are provided as generic parameters, this improves efficiency, especially
10659 if the procedures can be inlined, at the expense of duplicating code for
10660 multiple instantiations.
10662 @node GNAT.HTable (g-htable.ads)
10663 @section @code{GNAT.HTable} (@file{g-htable.ads})
10664 @cindex @code{GNAT.HTable} (@file{g-htable.ads})
10665 @cindex Hash tables
10668 A generic implementation of hash tables that can be used to hash arbitrary
10669 data. Provides two approaches, one a simple static approach, and the other
10670 allowing arbitrary dynamic hash tables.
10672 @node GNAT.IO (g-io.ads)
10673 @section @code{GNAT.IO} (@file{g-io.ads})
10674 @cindex @code{GNAT.IO} (@file{g-io.ads})
10676 @cindex Input/Output facilities
10679 A simple preealborable input-output package that provides a subset of
10680 simple Text_IO functions for reading characters and strings from
10681 Standard_Input, and writing characters, strings and integers to either
10682 Standard_Output or Standard_Error.
10684 @node GNAT.IO_Aux (g-io_aux.ads)
10685 @section @code{GNAT.IO_Aux} (@file{g-io_aux.ads})
10686 @cindex @code{GNAT.IO_Aux} (@file{g-io_aux.ads})
10688 @cindex Input/Output facilities
10690 Provides some auxiliary functions for use with Text_IO, including a test
10691 for whether a file exists, and functions for reading a line of text.
10693 @node GNAT.Lock_Files (g-locfil.ads)
10694 @section @code{GNAT.Lock_Files} (@file{g-locfil.ads})
10695 @cindex @code{GNAT.Lock_Files} (@file{g-locfil.ads})
10696 @cindex File locking
10697 @cindex Locking using files
10700 Provides a general interface for using files as locks. Can be used for
10701 providing program level synchronization.
10703 @node GNAT.MD5 (g-md5.ads)
10704 @section @code{GNAT.MD5} (@file{g-md5.ads})
10705 @cindex @code{GNAT.MD5} (@file{g-md5.ads})
10706 @cindex Message Digest MD5
10709 Implements the MD5 Message-Digest Algorithm as described in RFC 1321.
10711 @node GNAT.Most_Recent_Exception (g-moreex.ads)
10712 @section @code{GNAT.Most_Recent_Exception} (@file{g-moreex.ads})
10713 @cindex @code{GNAT.Most_Recent_Exception} (@file{g-moreex.ads})
10714 @cindex Exception, obtaining most recent
10717 Provides access to the most recently raised exception. Can be used for
10718 various logging purposes, including duplicating functionality of some
10719 Ada 83 implementation dependent extensions.
10721 @node GNAT.OS_Lib (g-os_lib.ads)
10722 @section @code{GNAT.OS_Lib} (@file{g-os_lib.ads})
10723 @cindex @code{GNAT.OS_Lib} (@file{g-os_lib.ads})
10724 @cindex Operating System interface
10725 @cindex Spawn capability
10728 Provides a range of target independent operating system interface functions,
10729 including time/date management, file operations, subprocess management,
10730 including a portable spawn procedure, and access to environment variables
10731 and error return codes.
10733 @node GNAT.Regexp (g-regexp.ads)
10734 @section @code{GNAT.Regexp} (@file{g-regexp.ads})
10735 @cindex @code{GNAT.Regexp} (@file{g-regexp.ads})
10736 @cindex Regular expressions
10737 @cindex Pattern matching
10740 A simple implementation of regular expressions, using a subset of regular
10741 expression syntax copied from familiar Unix style utilities. This is the
10742 simples of the three pattern matching packages provided, and is particularly
10743 suitable for ``file globbing'' applications.
10745 @node GNAT.Registry (g-regist.ads)
10746 @section @code{GNAT.Registry} (@file{g-regist.ads})
10747 @cindex @code{GNAT.Registry} (@file{g-regist.ads})
10748 @cindex Windows Registry
10751 This is a high level binding to the Windows registry. It is possible to
10752 do simple things like reading a key value, creating a new key. For full
10753 registry API, but at a lower level of abstraction, refer to the Win32.Winreg
10754 package provided with the Win32Ada binding
10756 @node GNAT.Regpat (g-regpat.ads)
10757 @section @code{GNAT.Regpat} (@file{g-regpat.ads})
10758 @cindex @code{GNAT.Regpat} (@file{g-regpat.ads})
10759 @cindex Regular expressions
10760 @cindex Pattern matching
10763 A complete implementation of Unix-style regular expression matching, copied
10764 from the original V7 style regular expression library written in C by
10765 Henry Spencer (and binary compatible with this C library).
10767 @node GNAT.Sockets (g-socket.ads)
10768 @section @code{GNAT.Sockets} (@file{g-socket.ads})
10769 @cindex @code{GNAT.Sockets} (@file{g-socket.ads})
10773 A high level and portable interface to develop sockets based applications.
10774 This package is based on the sockets thin binding found in GNAT.Sockets.Thin.
10775 Currently GNAT.Sockets is implemented on all native GNAT ports except for
10776 OpenVMS@. It is not implemented for the LynxOS@ cross port.
10778 @node GNAT.Source_Info (g-souinf.ads)
10779 @section @code{GNAT.Source_Info} (@file{g-souinf.ads})
10780 @cindex @code{GNAT.Source_Info} (@file{g-souinf.ads})
10781 @cindex Source Information
10784 Provides subprograms that give access to source code information known at
10785 compile time, such as the current file name and line number.
10787 @node GNAT.Spell_Checker (g-speche.ads)
10788 @section @code{GNAT.Spell_Checker} (@file{g-speche.ads})
10789 @cindex @code{GNAT.Spell_Checker} (@file{g-speche.ads})
10790 @cindex Spell checking
10793 Provides a function for determining whether one string is a plausible
10794 near misspelling of another string.
10796 @node GNAT.Spitbol.Patterns (g-spipat.ads)
10797 @section @code{GNAT.Spitbol.Patterns} (@file{g-spipat.ads})
10798 @cindex @code{GNAT.Spitbol.Patterns} (@file{g-spipat.ads})
10799 @cindex SPITBOL pattern matching
10800 @cindex Pattern matching
10803 A complete implementation of SNOBOL4 style pattern matching. This is the
10804 most elaborate of the pattern matching packages provided. It fully duplicates
10805 the SNOBOL4 dynamic pattern construction and matching capabilities, using the
10806 efficient algorithm developed by Robert Dewar for the SPITBOL system.
10808 @node GNAT.Spitbol (g-spitbo.ads)
10809 @section @code{GNAT.Spitbol} (@file{g-spitbo.ads})
10810 @cindex @code{GNAT.Spitbol} (@file{g-spitbo.ads})
10811 @cindex SPITBOL interface
10814 The top level package of the collection of SPITBOL-style functionality, this
10815 package provides basic SNOBOL4 string manipulation functions, such as
10816 Pad, Reverse, Trim, Substr capability, as well as a generic table function
10817 useful for constructing arbitrary mappings from strings in the style of
10818 the SNOBOL4 TABLE function.
10820 @node GNAT.Spitbol.Table_Boolean (g-sptabo.ads)
10821 @section @code{GNAT.Spitbol.Table_Boolean} (@file{g-sptabo.ads})
10822 @cindex @code{GNAT.Spitbol.Table_Boolean} (@file{g-sptabo.ads})
10823 @cindex Sets of strings
10824 @cindex SPITBOL Tables
10827 A library level of instantiation of @code{GNAT.Spitbol.Patterns.Table}
10828 for type @code{Standard.Boolean}, giving an implementation of sets of
10831 @node GNAT.Spitbol.Table_Integer (g-sptain.ads)
10832 @section @code{GNAT.Spitbol.Table_Integer} (@file{g-sptain.ads})
10833 @cindex @code{GNAT.Spitbol.Table_Integer} (@file{g-sptain.ads})
10834 @cindex Integer maps
10836 @cindex SPITBOL Tables
10839 A library level of instantiation of @code{GNAT.Spitbol.Patterns.Table}
10840 for type @code{Standard.Integer}, giving an implementation of maps
10841 from string to integer values.
10843 @node GNAT.Spitbol.Table_VString (g-sptavs.ads)
10844 @section @code{GNAT.Spitbol.Table_VString} (@file{g-sptavs.ads})
10845 @cindex @code{GNAT.Spitbol.Table_VString} (@file{g-sptavs.ads})
10846 @cindex String maps
10848 @cindex SPITBOL Tables
10851 A library level of instantiation of GNAT.Spitbol.Patterns.Table for
10852 a variable length string type, giving an implementation of general
10853 maps from strings to strings.
10855 @node GNAT.Table (g-table.ads)
10856 @section @code{GNAT.Table} (@file{g-table.ads})
10857 @cindex @code{GNAT.Table} (@file{g-table.ads})
10858 @cindex Table implementation
10859 @cindex Arrays, extendable
10862 A generic package providing a single dimension array abstraction where the
10863 length of the array can be dynamically modified.
10866 This package provides a facility similar to that of GNAT.Dynamic_Tables,
10867 except that this package declares a single instance of the table type,
10868 while an instantiation of GNAT.Dynamic_Tables creates a type that can be
10869 used to define dynamic instances of the table.
10871 @node GNAT.Task_Lock (g-tasloc.ads)
10872 @section @code{GNAT.Task_Lock} (@file{g-tasloc.ads})
10873 @cindex @code{GNAT.Task_Lock} (@file{g-tasloc.ads})
10874 @cindex Task synchronization
10875 @cindex Task locking
10879 A very simple facility for locking and unlocking sections of code using a
10880 single global task lock. Appropriate for use in situations where contention
10881 between tasks is very rarely expected.
10883 @node GNAT.Threads (g-thread.ads)
10884 @section @code{GNAT.Threads} (@file{g-thread.ads})
10885 @cindex @code{GNAT.Threads} (@file{g-thread.ads})
10886 @cindex Foreign threads
10887 @cindex Threads, foreign
10890 Provides facilities for creating and destroying threads with explicit calls.
10891 These threads are known to the GNAT run-time system. These subprograms are
10892 exported C-convention procedures intended to be called from foreign code.
10893 By using these primitives rather than directly calling operating systems
10894 routines, compatibility with the Ada tasking runt-time is provided.
10896 @node GNAT.Traceback (g-traceb.ads)
10897 @section @code{GNAT.Traceback} (@file{g-traceb.ads})
10898 @cindex @code{GNAT.Traceback} (@file{g-traceb.ads})
10899 @cindex Trace back facilities
10902 Provides a facility for obtaining non-symbolic traceback information, useful
10903 in various debugging situations.
10905 @node GNAT.Traceback.Symbolic (g-trasym.ads)
10906 @section @code{GNAT.Traceback.Symbolic} (@file{g-trasym.ads})
10907 @cindex @code{GNAT.Traceback.Symbolic} (@file{g-trasym.ads})
10908 @cindex Trace back facilities
10911 Provides symbolic traceback information that includes the subprogram
10912 name and line number information.
10914 @node Interfaces.C.Extensions (i-cexten.ads)
10915 @section @code{Interfaces.C.Extensions} (@file{i-cexten.ads})
10916 @cindex @code{Interfaces.C.Extensions} (@file{i-cexten.ads})
10919 This package contains additional C-related definitions, intended
10920 for use with either manually or automatically generated bindings
10923 @node Interfaces.C.Streams (i-cstrea.ads)
10924 @section @code{Interfaces.C.Streams} (@file{i-cstrea.ads})
10925 @cindex @code{Interfaces.C.Streams} (@file{i-cstrea.ads})
10926 @cindex C streams, interfacing
10929 This package is a binding for the most commonly used operations
10932 @node Interfaces.CPP (i-cpp.ads)
10933 @section @code{Interfaces.CPP} (@file{i-cpp.ads})
10934 @cindex @code{Interfaces.CPP} (@file{i-cpp.ads})
10935 @cindex C++ interfacing
10936 @cindex Interfacing, to C++
10939 This package provides facilities for use in interfacing to C++. It
10940 is primarily intended to be used in connection with automated tools
10941 for the generation of C++ interfaces.
10943 @node Interfaces.Os2lib (i-os2lib.ads)
10944 @section @code{Interfaces.Os2lib} (@file{i-os2lib.ads})
10945 @cindex @code{Interfaces.Os2lib} (@file{i-os2lib.ads})
10946 @cindex Interfacing, to OS/2
10947 @cindex OS/2 interfacing
10950 This package provides interface definitions to the OS/2 library.
10951 It is a thin binding which is a direct translation of the
10952 various @file{<bse@.h>} files.
10954 @node Interfaces.Os2lib.Errors (i-os2err.ads)
10955 @section @code{Interfaces.Os2lib.Errors} (@file{i-os2err.ads})
10956 @cindex @code{Interfaces.Os2lib.Errors} (@file{i-os2err.ads})
10957 @cindex OS/2 Error codes
10958 @cindex Interfacing, to OS/2
10959 @cindex OS/2 interfacing
10962 This package provides definitions of the OS/2 error codes.
10964 @node Interfaces.Os2lib.Synchronization (i-os2syn.ads)
10965 @section @code{Interfaces.Os2lib.Synchronization} (@file{i-os2syn.ads})
10966 @cindex @code{Interfaces.Os2lib.Synchronization} (@file{i-os2syn.ads})
10967 @cindex Interfacing, to OS/2
10968 @cindex Synchronization, OS/2
10969 @cindex OS/2 synchronization primitives
10972 This is a child package that provides definitions for interfacing
10973 to the @code{OS/2} synchronization primitives.
10975 @node Interfaces.Os2lib.Threads (i-os2thr.ads)
10976 @section @code{Interfaces.Os2lib.Threads} (@file{i-os2thr.ads})
10977 @cindex @code{Interfaces.Os2lib.Threads} (@file{i-os2thr.ads})
10978 @cindex Interfacing, to OS/2
10979 @cindex Thread control, OS/2
10980 @cindex OS/2 thread interfacing
10983 This is a child package that provides definitions for interfacing
10984 to the @code{OS/2} thread primitives.
10986 @node Interfaces.Packed_Decimal (i-pacdec.ads)
10987 @section @code{Interfaces.Packed_Decimal} (@file{i-pacdec.ads})
10988 @cindex @code{Interfaces.Packed_Decimal} (@file{i-pacdec.ads})
10989 @cindex IBM Packed Format
10990 @cindex Packed Decimal
10993 This package provides a set of routines for conversions to and
10994 from a packed decimal format compatible with that used on IBM
10997 @node Interfaces.VxWorks (i-vxwork.ads)
10998 @section @code{Interfaces.VxWorks} (@file{i-vxwork.ads})
10999 @cindex @code{Interfaces.VxWorks} (@file{i-vxwork.ads})
11000 @cindex Interfacing to VxWorks
11001 @cindex VxWorks, interfacing
11004 This package provides a limited binding to the VxWorks API.
11005 In particular, it interfaces with the
11006 VxWorks hardware interrupt facilities.
11008 @node Interfaces.VxWorks.IO (i-vxwoio.ads)
11009 @section @code{Interfaces.VxWorks.IO} (@file{i-vxwoio.ads})
11010 @cindex @code{Interfaces.VxWorks.IO} (@file{i-vxwoio.ads})
11011 @cindex Interfacing to VxWorks' I/O
11012 @cindex VxWorks, I/O interfacing
11013 @cindex VxWorks, Get_Immediate
11016 This package provides a limited binding to the VxWorks' I/O API.
11017 In particular, it provides procedures that enable the use of
11018 Get_Immediate under VxWorks.
11020 @node System.Address_Image (s-addima.ads)
11021 @section @code{System.Address_Image} (@file{s-addima.ads})
11022 @cindex @code{System.Address_Image} (@file{s-addima.ads})
11023 @cindex Address image
11024 @cindex Image, of an address
11027 This function provides a useful debugging
11028 function that gives an (implementation dependent)
11029 string which identifies an address.
11031 @node System.Assertions (s-assert.ads)
11032 @section @code{System.Assertions} (@file{s-assert.ads})
11033 @cindex @code{System.Assertions} (@file{s-assert.ads})
11035 @cindex Assert_Failure, exception
11038 This package provides the declaration of the exception raised
11039 by an run-time assertion failure, as well as the routine that
11040 is used internally to raise this assertion.
11042 @node System.Partition_Interface (s-parint.ads)
11043 @section @code{System.Partition_Interface} (@file{s-parint.ads})
11044 @cindex @code{System.Partition_Interface} (@file{s-parint.ads})
11045 @cindex Partition intefacing functions
11048 This package provides facilities for partition interfacing. It
11049 is used primarily in a distribution context when using Annex E
11052 @node System.Task_Info (s-tasinf.ads)
11053 @section @code{System.Task_Info} (@file{s-tasinf.ads})
11054 @cindex @code{System.Task_Info} (@file{s-tasinf.ads})
11055 @cindex Task_Info pragma
11058 This package provides target dependent functionality that is used
11059 to support the @code{Task_Info} pragma
11061 @node System.Wch_Cnv (s-wchcnv.ads)
11062 @section @code{System.Wch_Cnv} (@file{s-wchcnv.ads})
11063 @cindex @code{System.Wch_Cnv} (@file{s-wchcnv.ads})
11064 @cindex Wide Character, Representation
11065 @cindex Wide String, Conversion
11066 @cindex Representation of wide characters
11069 This package provides routines for converting between
11070 wide characters and a representation as a value of type
11071 @code{Standard.String}, using a specified wide character
11072 encoding method. It uses definitions in
11073 package @code{System.Wch_Con}.
11075 @node System.Wch_Con (s-wchcon.ads)
11076 @section @code{System.Wch_Con} (@file{s-wchcon.ads})
11077 @cindex @code{System.Wch_Con} (@file{s-wchcon.ads})
11080 This package provides definitions and descriptions of
11081 the various methods used for encoding wide characters
11082 in ordinary strings. These definitions are used by
11083 the package @code{System.Wch_Cnv}.
11085 @node Interfacing to Other Languages
11086 @chapter Interfacing to Other Languages
11088 The facilities in annex B of the Ada 95 Reference Manual are fully
11089 implemented in GNAT, and in addition, a full interface to C++ is
11093 * Interfacing to C::
11094 * Interfacing to C++::
11095 * Interfacing to COBOL::
11096 * Interfacing to Fortran::
11097 * Interfacing to non-GNAT Ada code::
11100 @node Interfacing to C
11101 @section Interfacing to C
11104 Interfacing to C with GNAT can use one of two approaches:
11108 The types in the package @code{Interfaces.C} may be used.
11110 Standard Ada types may be used directly. This may be less portable to
11111 other compilers, but will work on all GNAT compilers, which guarantee
11112 correspondence between the C and Ada types.
11116 Pragma @code{Convention C} maybe applied to Ada types, but mostly has no
11117 effect, since this is the default. The following table shows the
11118 correspondence between Ada scalar types and the corresponding C types.
11123 @item Short_Integer
11125 @item Short_Short_Integer
11129 @item Long_Long_Integer
11137 @item Long_Long_Float
11138 This is the longest floating-point type supported by the hardware.
11143 Ada enumeration types map to C enumeration types directly if pragma
11144 @code{Convention C} is specified, which causes them to have int
11145 length. Without pragma @code{Convention C}, Ada enumeration types map to
11146 8, 16, or 32 bits (i.e.@: C types @code{signed char}, @code{short}, @code{int}, respectively)
11147 depending on the number of values passed. This is the only case in which
11148 pragma @code{Convention C} affects the representation of an Ada type.
11151 Ada access types map to C pointers, except for the case of pointers to
11152 unconstrained types in Ada, which have no direct C equivalent.
11155 Ada arrays map directly to C arrays.
11158 Ada records map directly to C structures.
11161 Packed Ada records map to C structures where all members are bit fields
11162 of the length corresponding to the @code{@var{type}'Size} value in Ada.
11165 @node Interfacing to C++
11166 @section Interfacing to C++
11169 The interface to C++ makes use of the following pragmas, which are
11170 primarily intended to be constructed automatically using a binding generator
11171 tool, although it is possible to construct them by hand. Ada Core
11172 Technologies does not currently supply a suitable binding generator tool.
11174 Using these pragmas it is possible to achieve complete
11175 inter-operability between Ada tagged types and C class definitions.
11176 See @ref{Implementation Defined Pragmas} for more details.
11179 @item pragma CPP_Class ([Entity =>] @var{local_name})
11180 The argument denotes an entity in the current declarative region that is
11181 declared as a tagged or untagged record type. It indicates that the type
11182 corresponds to an externally declared C++ class type, and is to be laid
11183 out the same way that C++ would lay out the type.
11185 @item pragma CPP_Constructor ([Entity =>] @var{local_name})
11186 This pragma identifies an imported function (imported in the usual way
11187 with pragma @code{Import}) as corresponding to a C++ constructor.
11189 @item pragma CPP_Vtable @dots{}
11190 One @code{CPP_Vtable} pragma can be present for each component of type
11191 @code{CPP.Interfaces.Vtable_Ptr} in a record to which pragma @code{CPP_Class}
11195 @node Interfacing to COBOL
11196 @section Interfacing to COBOL
11199 Interfacing to COBOL is achieved as described in section B.4 of
11200 the Ada 95 reference manual.
11202 @node Interfacing to Fortran
11203 @section Interfacing to Fortran
11206 Interfacing to Fortran is achieved as described in section B.5 of the
11207 reference manual. The pragma @code{Convention Fortran}, applied to a
11208 multi-dimensional array causes the array to be stored in column-major
11209 order as required for convenient interface to Fortran.
11211 @node Interfacing to non-GNAT Ada code
11212 @section Interfacing to non-GNAT Ada code
11214 It is possible to specify the convention @code{Ada} in a pragma @code{Import} or
11215 pragma @code{Export}. However this refers to the calling conventions used
11216 by GNAT, which may or may not be similar enough to those used by
11217 some other Ada 83 or Ada 95 compiler to allow interoperation.
11219 If arguments types are kept simple, and if the foreign compiler generally
11220 follows system calling conventions, then it may be possible to integrate
11221 files compiled by other Ada compilers, provided that the elaboration
11222 issues are adequately addressed (for example by eliminating the
11223 need for any load time elaboration).
11225 In particular, GNAT running on VMS is designed to
11226 be highly compatible with the DEC Ada 83 compiler, so this is one
11227 case in which it is possible to import foreign units of this type,
11228 provided that the data items passed are restricted to simple scalar
11229 values or simple record types without variants, or simple array
11230 types with fixed bounds.
11232 @node Machine Code Insertions
11233 @chapter Machine Code Insertions
11236 Package @code{Machine_Code} provides machine code support as described
11237 in the Ada 95 Reference Manual in two separate forms:
11240 Machine code statements, consisting of qualified expressions that
11241 fit the requirements of RM section 13.8.
11243 An intrinsic callable procedure, providing an alternative mechanism of
11244 including machine instructions in a subprogram.
11247 The two features are similar, and both closely related to the mechanism
11248 provided by the asm instruction in the GNU C compiler. Full understanding
11249 and use of the facilities in this package requires understanding the asm
11250 instruction as described in
11251 @cite{Using and Porting the GNU Compiler Collection (GCC)} by Richard
11252 Stallman. Calls to the function @code{Asm} and the procedure @code{Asm}
11253 have identical semantic restrictions and effects as described below.
11254 Both are provided so that the procedure call can be used as a statement,
11255 and the function call can be used to form a code_statement.
11257 The first example given in the GCC documentation is the C @code{asm}
11260 asm ("fsinx %1 %0" : "=f" (result) : "f" (angle));
11264 The equivalent can be written for GNAT as:
11267 Asm ("fsinx %1 %0",
11268 My_Float'Asm_Output ("=f", result),
11269 My_Float'Asm_Input ("f", angle));
11272 The first argument to @code{Asm} is the assembler template, and is
11273 identical to what is used in GNU C@. This string must be a static
11274 expression. The second argument is the output operand list. It is
11275 either a single @code{Asm_Output} attribute reference, or a list of such
11276 references enclosed in parentheses (technically an array aggregate of
11279 The @code{Asm_Output} attribute denotes a function that takes two
11280 parameters. The first is a string, the second is the name of a variable
11281 of the type designated by the attribute prefix. The first (string)
11282 argument is required to be a static expression and designates the
11283 constraint for the parameter (e.g.@: what kind of register is
11284 required). The second argument is the variable to be updated with the
11285 result. The possible values for constraint are the same as those used in
11286 the RTL, and are dependent on the configuration file used to build the
11287 GCC back end. If there are no output operands, then this argument may
11288 either be omitted, or explicitly given as @code{No_Output_Operands}.
11290 The second argument of @code{@var{my_float}'Asm_Output} functions as
11291 though it were an @code{out} parameter, which is a little curious, but
11292 all names have the form of expressions, so there is no syntactic
11293 irregularity, even though normally functions would not be permitted
11294 @code{out} parameters. The third argument is the list of input
11295 operands. It is either a single @code{Asm_Input} attribute reference, or
11296 a list of such references enclosed in parentheses (technically an array
11297 aggregate of such references).
11299 The @code{Asm_Input} attribute denotes a function that takes two
11300 parameters. The first is a string, the second is an expression of the
11301 type designated by the prefix. The first (string) argument is required
11302 to be a static expression, and is the constraint for the parameter,
11303 (e.g.@: what kind of register is required). The second argument is the
11304 value to be used as the input argument. The possible values for the
11305 constant are the same as those used in the RTL, and are dependent on
11306 the configuration file used to built the GCC back end.
11308 If there are no input operands, this argument may either be omitted, or
11309 explicitly given as @code{No_Input_Operands}. The fourth argument, not
11310 present in the above example, is a list of register names, called the
11311 @dfn{clobber} argument. This argument, if given, must be a static string
11312 expression, and is a space or comma separated list of names of registers
11313 that must be considered destroyed as a result of the @code{Asm} call. If
11314 this argument is the null string (the default value), then the code
11315 generator assumes that no additional registers are destroyed.
11317 The fifth argument, not present in the above example, called the
11318 @dfn{volatile} argument, is by default @code{False}. It can be set to
11319 the literal value @code{True} to indicate to the code generator that all
11320 optimizations with respect to the instruction specified should be
11321 suppressed, and that in particular, for an instruction that has outputs,
11322 the instruction will still be generated, even if none of the outputs are
11323 used. See the full description in the GCC manual for further details.
11325 The @code{Asm} subprograms may be used in two ways. First the procedure
11326 forms can be used anywhere a procedure call would be valid, and
11327 correspond to what the RM calls ``intrinsic'' routines. Such calls can
11328 be used to intersperse machine instructions with other Ada statements.
11329 Second, the function forms, which return a dummy value of the limited
11330 private type @code{Asm_Insn}, can be used in code statements, and indeed
11331 this is the only context where such calls are allowed. Code statements
11332 appear as aggregates of the form:
11335 Asm_Insn'(Asm (@dots{}));
11336 Asm_Insn'(Asm_Volatile (@dots{}));
11339 In accordance with RM rules, such code statements are allowed only
11340 within subprograms whose entire body consists of such statements. It is
11341 not permissible to intermix such statements with other Ada statements.
11343 Typically the form using intrinsic procedure calls is more convenient
11344 and more flexible. The code statement form is provided to meet the RM
11345 suggestion that such a facility should be made available. The following
11346 is the exact syntax of the call to @code{Asm} (of course if named notation is
11347 used, the arguments may be given in arbitrary order, following the
11348 normal rules for use of positional and named arguments)
11352 [Template =>] static_string_EXPRESSION
11353 [,[Outputs =>] OUTPUT_OPERAND_LIST ]
11354 [,[Inputs =>] INPUT_OPERAND_LIST ]
11355 [,[Clobber =>] static_string_EXPRESSION ]
11356 [,[Volatile =>] static_boolean_EXPRESSION] )
11357 OUTPUT_OPERAND_LIST ::=
11359 | OUTPUT_OPERAND_ATTRIBUTE
11360 | (OUTPUT_OPERAND_ATTRIBUTE @{,OUTPUT_OPERAND_ATTRIBUTE@})
11361 OUTPUT_OPERAND_ATTRIBUTE ::=
11362 SUBTYPE_MARK'Asm_Output (static_string_EXPRESSION, NAME)
11363 INPUT_OPERAND_LIST ::=
11365 | INPUT_OPERAND_ATTRIBUTE
11366 | (INPUT_OPERAND_ATTRIBUTE @{,INPUT_OPERAND_ATTRIBUTE@})
11367 INPUT_OPERAND_ATTRIBUTE ::=
11368 SUBTYPE_MARK'Asm_Input (static_string_EXPRESSION, EXPRESSION)
11371 @node GNAT Implementation of Tasking
11372 @chapter GNAT Implementation of Tasking
11374 * Mapping Ada Tasks onto the Underlying Kernel Threads::
11375 * Ensuring Compliance with the Real-Time Annex::
11378 @node Mapping Ada Tasks onto the Underlying Kernel Threads
11379 @section Mapping Ada Tasks onto the Underlying Kernel Threads
11381 GNAT run-time system comprises two layers:
11384 @item GNARL (GNAT Run-time Layer)
11385 @item GNULL (GNAT Low-level Library)
11388 In GNAT, Ada's tasking services rely on a platform and OS independent
11389 layer known as GNARL@. This code is responsible for implementing the
11390 correct semantics of Ada's task creation, rendezvous, protected
11393 GNARL decomposes Ada's tasking semantics into simpler lower level
11394 operations such as create a thread, set the priority of a thread,
11395 yield, create a lock, lock/unlock, etc. The spec for these low-level
11396 operations constitutes GNULLI, the GNULL Interface. This interface is
11397 directly inspired from the POSIX real-time API@.
11399 If the underlying executive or OS implements the POSIX standard
11400 faithfully, the GNULL Interface maps as is to the services offered by
11401 the underlying kernel. Otherwise, some target dependent glue code maps
11402 the services offered by the underlying kernel to the semantics expected
11405 Whatever the underlying OS (VxWorks, UNIX, OS/2, Windows NT, etc.) the
11406 key point is that each Ada task is mapped on a thread in the underlying
11407 kernel. For example, in the case of VxWorks, one Ada task = one VxWorks task.
11409 In addition Ada task priorities map onto the underlying thread priorities.
11410 Mapping Ada tasks onto the underlying kernel threads has several advantages:
11415 The underlying scheduler is used to schedule the Ada tasks. This
11416 makes Ada tasks as efficient as kernel threads from a scheduling
11420 Interaction with code written in C containing threads is eased
11421 since at the lowest level Ada tasks and C threads map onto the same
11422 underlying kernel concept.
11425 When an Ada task is blocked during I/O the remaining Ada tasks are
11429 On multi-processor systems Ada Tasks can execute in parallel.
11432 @node Ensuring Compliance with the Real-Time Annex
11433 @section Ensuring Compliance with the Real-Time Annex
11435 The reader will be quick to notice that while mapping Ada tasks onto
11436 the underlying threads has significant advantages, it does create some
11437 complications when it comes to respecting the scheduling semantics
11438 specified in the real-time annex (Annex D).
11440 For instance Annex D requires that for the FIFO_Within_Priorities
11441 scheduling policy we have:
11444 When the active priority of a ready task that is not running
11445 changes, or the setting of its base priority takes effect, the
11446 task is removed from the ready queue for its old active priority
11447 and is added at the tail of the ready queue for its new active
11448 priority, except in the case where the active priority is lowered
11449 due to the loss of inherited priority, in which case the task is
11450 added at the head of the ready queue for its new active priority.
11453 While most kernels do put tasks at the end of the priority queue when
11454 a task changes its priority, (which respects the main
11455 FIFO_Within_Priorities requirement), almost none keep a thread at the
11456 beginning of its priority queue when its priority drops from the loss
11457 of inherited priority.
11459 As a result most vendors have provided incomplete Annex D implementations.
11461 The GNAT run-time, has a nice cooperative solution to this problem
11462 which ensures that accurate FIFO_Within_Priorities semantics are
11465 The principle is as follows. When an Ada task T is about to start
11466 running, it checks whether some other Ada task R with the same
11467 priority as T has been suspended due to the loss of priority
11468 inheritance. If this is the case, T yields and is placed at the end of
11469 its priority queue. When R arrives at the front of the queue it
11472 Note that this simple scheme preserves the relative order of the tasks
11473 that were ready to execute in the priority queue where R has been
11476 @node Code generation for array aggregates
11477 @chapter Code generation for array aggregates
11480 * Static constant aggregates with static bounds::
11481 * Constant aggregates with an unconstrained nominal types::
11482 * Aggregates with static bounds::
11483 * Aggregates with non-static bounds::
11484 * Aggregates in assignments statements::
11487 Aggregate have a rich syntax and allow the user to specify the values of
11488 complex data structures by means of a single construct. As a result, the
11489 code generated for aggregates can be quite complex and involve loops, case
11490 statements and multiple assignments. In the simplest cases, however, the
11491 compiler will recognize aggregates whose components and constraints are
11492 fully static, and in those cases the compiler will generate little or no
11493 executable code. The following is an outline of the code that GNAT generates
11494 for various aggregate constructs. For further details, the user will find it
11495 useful to examine the output produced by the -gnatG flag to see the expanded
11496 source that is input to the code generator. The user will also want to examine
11497 the assembly code generated at various levels of optimization.
11499 The code generated for aggregates depends on the context, the component values,
11500 and the type. In the context of an object declaration the code generated is
11501 generally simpler than in the case of an assignment. As a general rule, static
11502 component values and static subtypes also lead to simpler code.
11504 @node Static constant aggregates with static bounds
11505 @section Static constant aggregates with static bounds
11507 For the declarations:
11509 type One_Dim is array (1..10) of integer;
11510 ar0 : constant One_Dim := ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
11513 GNAT generates no executable code: the constant ar0 is placed in static memory.
11514 The same is true for constant aggregates with named associations:
11517 Cr1 : constant One_Dim := (4 => 16, 2 => 4, 3 => 9, 1=> 1);
11518 Cr3 : constant One_Dim := (others => 7777);
11521 The same is true for multidimensional constant arrays such as:
11524 type two_dim is array (1..3, 1..3) of integer;
11525 Unit : constant two_dim := ( (1,0,0), (0,1,0), (0,0,1));
11528 The same is true for arrays of one-dimensional arrays: the following are
11532 type ar1b is array (1..3) of boolean;
11533 type ar_ar is array (1..3) of ar1b;
11534 None : constant ar1b := (others => false); -- fully static
11535 None2 : constant ar_ar := (1..3 => None); -- fully static
11538 However, for multidimensional aggregates with named associations, GNAT will
11539 generate assignments and loops, even if all associations are static. The
11540 following two declarations generate a loop for the first dimension, and
11541 individual component assignments for the second dimension:
11544 Zero1: constant two_dim := (1..3 => (1..3 => 0));
11545 Zero2: constant two_dim := (others => (others => 0));
11548 @node Constant aggregates with an unconstrained nominal types
11549 @section Constant aggregates with an unconstrained nominal types
11551 In such cases the aggregate itself establishes the subtype, so that associations
11552 with @code{others} cannot be used. GNAT determines the bounds for the actual
11553 subtype of the aggregate, and allocates the aggregate statically as well. No
11554 code is generated for the following:
11557 type One_Unc is array (natural range <>) of integer;
11558 Cr_Unc : constant One_Unc := (12,24,36);
11561 @node Aggregates with static bounds
11562 @section Aggregates with static bounds
11564 In all previous examples the aggregate was the initial (and immutable) value
11565 of a constant. If the aggregate initializes a variable, then code is generated
11566 for it as a combination of individual assignments and loops over the target
11567 object. The declarations
11570 Cr_Var1 : One_Dim := (2, 5, 7, 11);
11571 Cr_Var2 : One_Dim := (others > -1);
11574 generate the equivalent of
11582 for I in Cr_Var2'range loop
11583 Cr_Var2 (I) := =-1;
11587 @node Aggregates with non-static bounds
11588 @section Aggregates with non-static bounds
11590 If the bounds of the aggregate are not statically compatible with the bounds
11591 of the nominal subtype of the target, then constraint checks have to be
11592 generated on the bounds. For a multidimensional array, constraint checks may
11593 have to be applied to sub-arrays individually, if they do not have statically
11594 compatible subtypes.
11596 @node Aggregates in assignments statements
11597 @section Aggregates in assignments statements
11599 In general, aggregate assignment requires the construction of a temporary,
11600 and a copy from the temporary to the target of the assignment. This is because
11601 it is not always possible to convert the assignment into a series of individual
11602 component assignments. For example, consider the simple case:
11608 This cannot be converted into:
11615 So the aggregate has to be built first in a separate location, and then
11616 copied into the target. GNAT recognizes simple cases where this intermediate
11617 step is not required, and the assignments can be performed in place, directly
11618 into the target. The following sufficient criteria are applied:
11621 @item The bounds of the aggregate are static, and the associations are static.
11622 @item The components of the aggregate are static constants, names of
11623 simple variables that are not renamings, or expressions not involving
11624 indexed components whose operands obey these rules.
11627 If any of these conditions are violated, the aggregate will be built in
11628 a temporary (created either by the front-end or the code generator) and then
11629 that temporary will be copied onto the target.
11632 @node Specialized Needs Annexes
11633 @chapter Specialized Needs Annexes
11636 Ada 95 defines a number of specialized needs annexes, which are not
11637 required in all implementations. However, as described in this chapter,
11638 GNAT implements all of these special needs annexes:
11641 @item Systems Programming (Annex C)
11642 The Systems Programming Annex is fully implemented.
11644 @item Real-Time Systems (Annex D)
11645 The Real-Time Systems Annex is fully implemented.
11647 @item Distributed Systems (Annex E)
11648 Stub generation is fully implemented in the GNAT compiler. In addition,
11649 a complete compatible PCS is available as part of the GLADE system,
11650 a separate product. When the two
11651 products are used in conjunction, this annex is fully implemented.
11653 @item Information Systems (Annex F)
11654 The Information Systems annex is fully implemented.
11656 @item Numerics (Annex G)
11657 The Numerics Annex is fully implemented.
11659 @item Safety and Security (Annex H)
11660 The Safety and Security annex is fully implemented.
11664 @node Compatibility Guide
11665 @chapter Compatibility Guide
11668 This chapter contains sections that describe compatibility issues between
11669 GNAT and other Ada 83 and Ada 95 compilation systems, to aid in porting
11670 applications developed in other Ada environments.
11673 * Compatibility with Ada 83::
11674 * Compatibility with DEC Ada 83::
11675 * Compatibility with Other Ada 95 Systems::
11676 * Representation Clauses::
11679 @node Compatibility with Ada 83
11680 @section Compatibility with Ada 83
11681 @cindex Compatibility (between Ada 83 and Ada 95)
11684 Ada 95 is designed to be highly upwards compatible with Ada 83. In
11685 particular, the design intention is that the difficulties associated
11686 with moving from Ada 83 to Ada 95 should be no greater than those
11687 that occur when moving from one Ada 83 system to another.
11689 However, there are a number of points at which there are minor
11690 incompatibilities. The Ada 95 Annotated Reference Manual contains
11691 full details of these issues,
11692 and should be consulted for a complete treatment.
11694 following are the most likely issues to be encountered.
11697 @item Character range
11698 The range of @code{Standard.Character} is now the full 256 characters of Latin-1,
11699 whereas in most Ada 83 implementations it was restricted to 128 characters.
11700 This may show up as compile time or runtime errors. The desirable fix is to
11701 adapt the program to accommodate the full character set, but in some cases
11702 it may be convenient to define a subtype or derived type of Character that
11703 covers only the restricted range.
11706 @item New reserved words
11707 The identifiers @code{abstract}, @code{aliased}, @code{protected},
11708 @code{requeue}, @code{tagged}, and @code{until} are reserved in Ada 95.
11709 Existing Ada 83 code using any of these identifiers must be edited to
11710 use some alternative name.
11712 @item Freezing rules
11713 The rules in Ada 95 are slightly different with regard to the point at
11714 which entities are frozen, and representation pragmas and clauses are
11715 not permitted past the freeze point. This shows up most typically in
11716 the form of an error message complaining that a representation item
11717 appears too late, and the appropriate corrective action is to move
11718 the item nearer to the declaration of the entity to which it refers.
11720 A particular case is that representation pragmas (including the
11721 extended DEC Ada 83 compatibility pragmas such as @code{Export_Procedure}), cannot
11722 be applied to a subprogram body. If necessary, a separate subprogram
11723 declaration must be introduced to which the pragma can be applied.
11725 @item Optional bodies for library packages
11726 In Ada 83, a package that did not require a package body was nevertheless
11727 allowed to have one. This lead to certain surprises in compiling large
11728 systems (situations in which the body could be unexpectedly ignored). In
11729 Ada 95, if a package does not require a body then it is not permitted to
11730 have a body. To fix this problem, simply remove a redundant body if it
11731 is empty, or, if it is non-empty, introduce a dummy declaration into the
11732 spec that makes the body required. One approach is to add a private part
11733 to the package declaration (if necessary), and define a parameterless
11734 procedure called Requires_Body, which must then be given a dummy
11735 procedure body in the package body, which then becomes required.
11737 @item @code{Numeric_Error} is now the same as @code{Constraint_Error}
11738 In Ada 95, the exception @code{Numeric_Error} is a renaming of @code{Constraint_Error}.
11739 This means that it is illegal to have separate exception handlers for
11740 the two exceptions. The fix is simply to remove the handler for the
11741 @code{Numeric_Error} case (since even in Ada 83, a compiler was free to raise
11742 @code{Constraint_Error} in place of @code{Numeric_Error} in all cases).
11744 @item Indefinite subtypes in generics
11745 In Ada 83, it was permissible to pass an indefinite type (e.g.@: @code{String}) as
11746 the actual for a generic formal private type, but then the instantiation
11747 would be illegal if there were any instances of declarations of variables
11748 of this type in the generic body. In Ada 95, to avoid this clear violation
11749 of the contract model, the generic declaration clearly indicates whether
11750 or not such instantiations are permitted. If a generic formal parameter
11751 has explicit unknown discriminants, indicated by using @code{(<>)} after the
11752 type name, then it can be instantiated with indefinite types, but no
11753 variables can be declared of this type. Any attempt to declare a variable
11754 will result in an illegality at the time the generic is declared. If the
11755 @code{(<>)} notation is not used, then it is illegal to instantiate the generic
11756 with an indefinite type. This will show up as a compile time error, and
11757 the fix is usually simply to add the @code{(<>)} to the generic declaration.
11760 All implementations of GNAT provide a switch that causes GNAT to operate
11761 in Ada 83 mode. In this mode, some but not all compatibility problems
11762 of the type described above are handled automatically. For example, the
11763 new Ada 95 protected keywords are not recognized in this mode. However,
11764 in practice, it is usually advisable to make the necessary modifications
11765 to the program to remove the need for using this switch.
11767 @node Compatibility with Other Ada 95 Systems
11768 @section Compatibility with Other Ada 95 Systems
11771 Providing that programs avoid the use of implementation dependent and
11772 implementation defined features of Ada 95, as documented in the Ada 95
11773 reference manual, there should be a high degree of portability between
11774 GNAT and other Ada 95 systems. The following are specific items which
11775 have proved troublesome in moving GNAT programs to other Ada 95
11776 compilers, but do not affect porting code to GNAT@.
11779 @item Ada 83 Pragmas and Attributes
11780 Ada 95 compilers are allowed, but not required, to implement the missing
11781 Ada 83 pragmas and attributes that are no longer defined in Ada 95.
11782 GNAT implements all such pragmas and attributes, eliminating this as
11783 a compatibility concern, but some other Ada 95 compilers reject these
11784 pragmas and attributes.
11786 @item Special-needs Annexes
11787 GNAT implements the full set of special needs annexes. At the
11788 current time, it is the only Ada 95 compiler to do so. This means that
11789 programs making use of these features may not be portable to other Ada
11790 95 compilation systems.
11792 @item Representation Clauses
11793 Some other Ada 95 compilers implement only the minimal set of
11794 representation clauses required by the Ada 95 reference manual. GNAT goes
11795 far beyond this minimal set, as described in the next section.
11798 @node Representation Clauses
11799 @section Representation Clauses
11802 The Ada 83 reference manual was quite vague in describing both the minimal
11803 required implementation of representation clauses, and also their precise
11804 effects. The Ada 95 reference manual is much more explicit, but the minimal
11805 set of capabilities required in Ada 95 is quite limited.
11807 GNAT implements the full required set of capabilities described in the
11808 Ada 95 reference manual, but also goes much beyond this, and in particular
11809 an effort has been made to be compatible with existing Ada 83 usage to the
11810 greatest extent possible.
11812 A few cases exist in which Ada 83 compiler behavior is incompatible with
11813 requirements in the Ada 95 reference manual. These are instances of
11814 intentional or accidental dependence on specific implementation dependent
11815 characteristics of these Ada 83 compilers. The following is a list of
11816 the cases most likely to arise in existing legacy Ada 83 code.
11819 @item Implicit Packing
11820 Some Ada 83 compilers allowed a Size specification to cause implicit
11821 packing of an array or record. This could cause expensive implicit
11822 conversions for change of representation in the presence of derived
11823 types, and the Ada design intends to avoid this possibility.
11824 Subsequent AI's were issued to make it clear that such implicit
11825 change of representation in response to a Size clause is inadvisable,
11826 and this recommendation is represented explicitly in the Ada 95 RM
11827 as implementation advice that is followed by GNAT@.
11828 The problem will show up as an error
11829 message rejecting the size clause. The fix is simply to provide
11830 the explicit pragma @code{Pack}, or for more fine tuned control, provide
11831 a Component_Size clause.
11833 @item Meaning of Size Attribute
11834 The Size attribute in Ada 95 for discrete types is defined as being the
11835 minimal number of bits required to hold values of the type. For example,
11836 on a 32-bit machine, the size of Natural will typically be 31 and not
11837 32 (since no sign bit is required). Some Ada 83 compilers gave 31, and
11838 some 32 in this situation. This problem will usually show up as a compile
11839 time error, but not always. It is a good idea to check all uses of the
11840 'Size attribute when porting Ada 83 code. The GNAT specific attribute
11841 Object_Size can provide a useful way of duplicating the behavior of
11842 some Ada 83 compiler systems.
11844 @item Size of Access Types
11845 A common assumption in Ada 83 code is that an access type is in fact a pointer,
11846 and that therefore it will be the same size as a System.Address value. This
11847 assumption is true for GNAT in most cases with one exception. For the case of
11848 a pointer to an unconstrained array type (where the bounds may vary from one
11849 value of the access type to another), the default is to use a ``fat pointer'',
11850 which is represented as two separate pointers, one to the bounds, and one to
11851 the array. This representation has a number of advantages, including improved
11852 efficiency. However, it may cause some difficulties in porting existing Ada 83
11853 code which makes the assumption that, for example, pointers fit in 32 bits on
11854 a machine with 32-bit addressing.
11856 To get around this problem, GNAT also permits the use of ``thin pointers'' for
11857 access types in this case (where the designated type is an unconstrained array
11858 type). These thin pointers are indeed the same size as a System.Address value.
11859 To specify a thin pointer, use a size clause for the type, for example:
11862 type X is access all String;
11863 for X'Size use Standard'Address_Size;
11867 which will cause the type X to be represented using a single pointer. When using
11868 this representation, the bounds are right behind the array. This representation
11869 is slightly less efficient, and does not allow quite such flexibility in the
11870 use of foreign pointers or in using the Unrestricted_Access attribute to create
11871 pointers to non-aliased objects. But for any standard portable use of the access
11872 type it will work in a functionally correct manner and allow porting of existing
11873 code. Note that another way of forcing a thin pointer representation is to use
11874 a component size clause for the element size in an array, or a record
11875 representation clause for an access field in a record.
11878 @node Compatibility with DEC Ada 83
11879 @section Compatibility with DEC Ada 83
11882 The VMS version of GNAT fully implements all the pragmas and attributes
11883 provided by DEC Ada 83, as well as providing the standard DEC Ada 83
11884 libraries, including Starlet. In addition, data layouts and parameter
11885 passing conventions are highly compatible. This means that porting
11886 existing DEC Ada 83 code to GNAT in VMS systems should be easier than
11887 most other porting efforts. The following are some of the most
11888 significant differences between GNAT and DEC Ada 83.
11891 @item Default floating-point representation
11892 In GNAT, the default floating-point format is IEEE, whereas in DEC Ada 83,
11893 it is VMS format. GNAT does implement the necessary pragmas
11894 (Long_Float, Float_Representation) for changing this default.
11897 The package System in GNAT exactly corresponds to the definition in the
11898 Ada 95 reference manual, which means that it excludes many of the
11899 DEC Ada 83 extensions. However, a separate package Aux_DEC is provided
11900 that contains the additional definitions, and a special pragma,
11901 Extend_System allows this package to be treated transparently as an
11902 extension of package System.
11905 The definitions provided by Aux_DEC are exactly compatible with those
11906 in the DEC Ada 83 version of System, with one exception. DEC Ada provides
11907 the following declarations:
11910 TO_ADDRESS(INTEGER)
11911 TO_ADDRESS(UNSIGNED_LONGWORD)
11912 TO_ADDRESS(universal_integer)
11916 The version of TO_ADDRESS taking a universal integer argument is in fact
11917 an extension to Ada 83 not strictly compatible with the reference manual.
11918 In GNAT, we are constrained to be exactly compatible with the standard,
11919 and this means we cannot provide this capability. In DEC Ada 83, the
11920 point of this definition is to deal with a call like:
11923 TO_ADDRESS (16#12777#);
11927 Normally, according to the Ada 83 standard, one would expect this to be
11928 ambiguous, since it matches both the INTEGER and UNSIGNED_LONGWORD forms
11929 of TO_ADDRESS@. However, in DEC Ada 83, there is no ambiguity, since the
11930 definition using universal_integer takes precedence.
11932 In GNAT, since the version with universal_integer cannot be supplied, it is
11933 not possible to be 100% compatible. Since there are many programs using
11934 numeric constants for the argument to TO_ADDRESS, the decision in GNAT was
11935 to change the name of the function in the UNSIGNED_LONGWORD case, so the
11936 declarations provided in the GNAT version of AUX_Dec are:
11939 function To_Address (X : Integer) return Address;
11940 pragma Pure_Function (To_Address);
11942 function To_Address_Long (X : Unsigned_Longword)
11944 pragma Pure_Function (To_Address_Long);
11948 This means that programs using TO_ADDRESS for UNSIGNED_LONGWORD must
11949 change the name to TO_ADDRESS_LONG@.
11951 @item Task_Id values
11952 The Task_Id values assigned will be different in the two systems, and GNAT
11953 does not provide a specified value for the Task_Id of the environment task,
11954 which in GNAT is treated like any other declared task.
11957 For full details on these and other less significant compatibility issues,
11958 see appendix E of the Digital publication entitled @cite{DEC Ada, Technical
11959 Overview and Comparison on DIGITAL Platforms}.
11961 For GNAT running on other than VMS systems, all the DEC Ada 83 pragmas and
11962 attributes are recognized, although only a subset of them can sensibly
11963 be implemented. The description of pragmas in this reference manual
11964 indicates whether or not they are applicable to non-VMS systems.
11967 @c GNU Free Documentation License
11969 @node Index,,GNU Free Documentation License, Top