Skip to content

Latest commit

 

History

History

intro-to-ada

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Introduction to Ada Tutorial

Ada project 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 :

forward_declaration Example

Code example forward_declaration consists of

We can build/execute this project as follows :

> build clean run

Book Example

Code example Book consists of

> 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

Week Example

Code example Week consists of

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 Monday

and use option -debug to see further build details such as the arguments passed to the executed commands.

Enumeration Example

Code example Enumeration consists of

Greet Example

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 :

[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 or unused (case insensitive).

mics/May 2024