Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use “separate" keyword

Tags:

ada

I am unable to figure out keyword separate in Ada and its depth concept. Please help me to understand by giving a small example?

Lets say I have a nested procedure

with ada.text_io; use ada.text_io;
procedure main is
   procedure proc is
   begin
      put_line ("i am proc");
   end proc;
begin
   put_line ("main");
end main;

How to use separate keyword ?

like image 203
Santosh Gupta Avatar asked Jan 18 '15 07:01

Santosh Gupta


2 Answers

You primarily use the separate keyword to achieve one of 2 effects.

  1. OS specific actions. (Put 2 versions of the procedure / functions in different directories, and compile for 2 different targets)
  2. Separation of a lengthy procedure from surrounding code.

Here is an example to show the syntax.

package_x.ads

package Package_X is

   procedure Foo;
   procedure Sep;

end Package_X;

package_x.adb

package body Package_X is

   procedure Foo is 
   begin
      null;
   end Foo;

   procedure Sep is separate;

end Package_X;

package_x-sep.adb

separate (Package_X) procedure Sep is 
begin
   null;
end Sep;
like image 127
NWS Avatar answered Oct 13 '22 20:10

NWS


The separate keyword creates a unit of compilation, a subunit, that is compiled independently. The parameter of separate refers to the package in which the subunit is a sub unit of.

So if you had a package body X, then you remove procedure Y from it, you create a sub unit of X by creating a new file in which you place Y, and put "separate(X)" at the start of the file, to indicate that Y is really part of X.

like image 33
Jool Avatar answered Oct 13 '22 20:10

Jool