-- Demonstrates global varibles. Accomplishes nothing.
-- Demonstrates where to declare variables for main program
with ada.integer_text_io; use ada.integer_text_io;
with ada.text_io; use ada.text_io;
procedure globals1 is
MaxValue: constant Natural := 10; -- Global constant - Okay
subtype MyRange is Integer range 1 .. MaxValue; -- Global type - Okay
-- These variables are GLOBAL to and visible in procedures p and q. NOT OKAY.
m1, m2: MyRange; -- Variables for main should NOT go here
procedure p(m: MyRange) is
someLocal: Natural;
begin
put_line("Don't do this!");
m2 := 3;
m1 := 2 * m2;
someLocal := m1 + m2;
end p;
procedure q is begin
p(3);
end q;
v1, v2: Natural; -- Variables for main must go here
begin -- main
get(v1);
v2 := v1 + 1;
q;
end globals1;