Introduction to Ada Tutorial ↩
Directory intro-to-ada\ contains Ada code examples coming from AdaCore's online tutorial Introduction to Ada.
|
Code examples presented in this document can be built in two ways :
- the batch file
build.bat
calls theGNATmake
build tool (try option-help
to display other features) - the GPR tools – e.g.
gprclean
andgprbuild
– get their build information from the project filemain.gpr
1.
Code example forward_declaration
consists of
- the source file
mutually_recursive_subprograms.adb
- the project file
build.gpr
and - the batch file
build.bat
.
We can build/execute this project as follows :
> build clean run
Book
Example ▴
Code example Book
consists of
- the five source files
book.ads
,book.adb
,book-additional_operations.ads
,book-additional_operations.adb
andmain.adb
. - the project file
build.gpr
and - the batch file
build.bat
.
> build clean run Book Title: Visible for my children Book Author: Author not visible for my children > gprclean -q & gprbuild -q & target\Book.exe Book Title: Visible for my children Book Author: Author not visible for my children
Code example Week
consists of
- the two source files
Week.ads
andMain.adb
, - the project file
build.gpr
and - the batch file
build.bat
.
We can build/execute this project as follows :
> build clean run First day of the week is Monday > gprclean -q & gprbuild -q & target\Week.exe First day of the week is Monday
🔎 Use option
-verbose
to display progress information :> build -verbose clean run Delete directory "target" Compile 2 Ada source files to object directory "target\obj" Execute program "Week.exe" First day of the week is Mondayand use option
-debug
to see further build details such as the arguments passed to the executed commands.
Enumeration
Example ▴
Code example Enumeration
consists of
- the source file
enumeration_example.adb
, - the project file
build.gpr
and - the batch file
build.bat
.
We can build/execute this code example as follows (source file Greet.adb
, project file build.gpr
) :
> build -verbose run Compile 1 Ada source files to object directory "target\obj" Execute program "Greet.exe" 2 3 5 7 11 > gprbuild & target\Greet.exe using project file main.gpr Compile [Ada] greet.adb greet.adb:11:04: warning: "Arr" is not modified, could be declared constant [-gnatwk] Bind [gprbind] greet.bexch [Ada] greet.ali Link [link] greet.adb 2 3 5 7 11
Footnotes ▴
[1] GNAT Project Files ↩
- TODO: Executable file names.
-
Some project file examples :
AdaCore/gprbuild
project:gprbuild.gpr
[2] GNAT Warnings ↩
-
With all GNAT warnings activated, it becomes even harder to ignore the result of a function, because unused variables will be flagged. We then have two solutions to silence this warning:
- Either we annotate the variable with
pragma Unreferenced
, e.g.:B : Boolean := Read_Int (Stream, My_Int); pragma Unreferenced (B);
- Or we give the variable a name that contains any of the strings
discard
,dummy
,ignore
,junk
orunused
(case insensitive).
- Either we annotate the variable with