DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B1022: a main subprogram's profile

Catalog status: active. Default severity: error. Stable name: main-profile. Family: Names and declarations.

A program's main subprogram is a procedure without parameters, or a function without parameters whose result is of an integer type, which becomes the program's exit status. Ada leaves the profile of a main subprogram to the implementation (RM 10.2(29)); these are the ones Verada runs and builds. A main subprogram with parameters, or a function of another result type, is refused when the program is run or built.

Example (Vada)

procedure Main (Count : Integer) is   --  a main subprogram has no parameters
begin
   null;
end Main;

What to do

Read the command line in a parameterless main with Ada.Command_Line, and pass what it reads to the subprogram that needs it:

with Ada.Command_Line;
procedure Main is
   procedure Work (Count : Integer) is
   begin
      null;
   end Work;
begin
   if Ada.Command_Line.Argument_Count > 0 then
      Work (Integer'Value (Ada.Command_Line.Argument (1)));
   end if;
end Main;

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See names and declarations, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.