1
votes

It seems so simple but this does not compile:

procedure Main is
begin
   exit 1;
end Main;

When compiled with gprbuild, yields:

Compile
   [Ada]          main.adb
main.adb:3:04: cannot exit from program unit or accept statement
main.adb:3:08: missing ";"
gprbuild: *** compilation phase failed

The exit keyword in Ada clearly doesn't do what it does in other programming languages. So how do you exit from the ada main procedure with an error code?

2
This seems to be related to stackoverflow.com/questions/28487175/… You might want to give a look at the answer, it uses Gnat library (so not as portable as egilhh answer). - G_Zeus

2 Answers

4
votes

How about:

with Ada.Command_Line;

procedure Main is
begin
   Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
end Main;
0
votes

Make your Ada main program a function, not a procedure, and return the exit code you want:

function Main return integer is
begin
   return 1;
end Main;