Skip to content

Instantly share code, notes, and snippets.

@Julio-Guerra
Created May 23, 2012 13:59
Show Gist options
  • Save Julio-Guerra/2775380 to your computer and use it in GitHub Desktop.
Save Julio-Guerra/2775380 to your computer and use it in GitHub Desktop.
Separating "interface constants" (types, package renames & constants values) from the interface declaration in Ada using sibling packages
with Misc.Interface; use Misc.Interface;
with Misc.Types; use Misc.Types;
procedure Main is
X : A := A'(Bar); -- separate type definitions ok
begin
F(X);
F(Cst); -- separate constant values definitions ok
Rename_Me.Put_Line(A'Image(X)); -- separate package renames ok
end Main;
with Misc.Constants; use Misc.Constants;
-- Interface and Types are sibling packages which is the only
-- way not to get a circular reference error (by keeping the
-- interface is misc.ads which would be the parent package of
-- Constants).
-- when trying to separate part of the specification file.
package Misc.Interface is
procedure F(X : A);
end Misc.Types;
with Ada.Text_IO; -- for example
package Misc.Constants is
-- Type definition
type A is (Foo, Bar);
-- Package rename
package Rename_Me renames Text_IO;
-- Constant value
Cst : constant A := A'(Foo);
end Misc.Constants;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment