Function prototype: Difference between revisions

Demonstrate packages
m (omissions)
(Demonstrate packages)
Line 14:
 
=={{header|Ada}}==
In Ada, prototypes are called specifications.
* Prototypes must be an exact copy of everything prior to the "is" statement for a function or procedure.
* All prototypesSpecifications must appearbe inan aexact declarativecopy section,of ie:everything beforeprior ato the "beginis" statement for a function or procedure.
* All specifications must appear in a declarative section, ie: before a "begin" statement.
* For a main program, prototypesspecifications are only necessary if a function call appears in the source before the function definition.
* For a with'd filepackage, prototypesspecifications must appear as part of the specification(.ads) file, and do not appear in the body file(.adb) (The file extensions apply to Gnat Ada and may not apply to all compilers).
<lang Ada>function noargs return Integer;
function twoargs (a, b : Integer) return Integer;
Line 30 ⟶ 31:
next : accBox; -- including that a box holds access to other boxes
end record;</lang>
Example of a package specification (i.e. prototype).:
<lang Ada>
package Stack is
procedure Push(Object:Integer);
function Pull return Integer;
end Stack;
</lang>
 
Example of a package body:
<lang Ada>
package body Stack is
 
procedure Push(Object:Integer) is
begin
-- implementation goes here
end;
 
function Pull return Integer;
begin
-- implementation goes here
end;
 
end Stack;
</lang>
 
To use the package and function
<lang Ada>
with Stack;
procedure Main is
N:integer:=5;
begin
Push(N);
...
N := Pull;
end Main;
</lang>
 
=={{header|C}}==
Anonymous user