Function prototype: Difference between revisions

Added Ada
(Omitted task from python. Also, cleaned markup a little (moved omits and category in nonsensical places))
(Added Ada)
Line 10:
* Example of prototype declarations for subroutines or procedures (if these differ from functions)
* An explanation and example of any special forms of prototyping not covered by the above
 
=={{header|Ada}}==
* Prototypes must be an exact copy of everything prior to the "is" statement for a function or procedure.
* All prototypes must appear in a declarative section, ie: before a "begin" statement.
* For a main program, prototypes are only necessary if a function call appears in the source before the function definition.
* For a with'd file, prototypes must appear as part of the specification(.ads) file, and do not appear in the body file(.adb).
<lang Ada>function noargs return Integer;
function twoargs (a, b : Integer) return Integer;
-- varargs do not exist
function optionalargs (a, b : Integer := 0) return Integer;
-- all parameters are always named, only calling by name differs
procedure dostuff (a : Integer);</lang>
Other Prototyping: Since pointers are not generic in Ada, a type must be defined before one can have a pointer to that type, thus for making linked-list type semantics another trivial prototyping exists:
<lang Ada>type Box; -- tell Ada a box exists (undefined yet)
type accBox is access Box; -- define a pointer to a box
type Box is record -- later define what a box is
next : accBox; -- including that a box holds access to other boxes
end record;</lang>
 
=={{header|Common Lisp}}==
Anonymous user