Some languages provide the facility to declare functions and subroutines through the use of function prototyping.



Task

Demonstrate the methods available for declaring prototypes within the language. The provided solutions should include:

 An explanation of any placement restrictions for prototype declarations
 A prototype declaration for a function that does not require arguments
 A prototype declaration for a function that requires two arguments
 A prototype declaration for a function that utilizes varargs
 A prototype declaration for a function that utilizes optional arguments
 A prototype declaration for a function that utilizes named parameters
 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


Languages that do not provide function prototyping facilities should be omitted from this task.




 
'DECLARE FUNCTION' ABBREVIATED TO '!'
 
!  f()                     ' a procedure with no params
!  f(int a)                ' with 1 int param
!  f(int *a)               ' with 1 int pointer param
!  f(int a, int b, inc c)  ' with 3 int params
!  f(int a,b,c)            ' compaction with 3 int params
!  f(string s, int a,b)    ' with 1 string and 2 int params
!  f() as string           ' function returning a string
!  f(string s) as string   ' with 1 string param
! *f(string s) as string   ' as a function pointer: @f=address
!  f(string s, optional i) ' with opptional param
!  f(string s = "Hello")   ' optional param with default value
!  f(int n, ...)           ' 1 specific param and varargs
!  f(...)                  ' any params or none
 
'TRADITIONAL BASIC DECLARATIONS
declare sub f( s as string, i as long, j as long)  ' byref by default
declare function f( byref s as string, byval i as long, byval j as long) as string
 
'C-STYLE DECLARATIONS
void f(string *s, long i, long j)
string f(string *s, long i, long j)
 
 
 
'BLOCK DIRECTIVES FOR FUNCTION PROTOTYPES:
 
extern                      ' shareable stdcall functions
 
extern  lib "xyz.dll"       ' for accessing functions in xyz Dynamic Link Library
 
extern export               ' functions to be exported if this is a DLL
 
extern virtual              ' for accssing interfaces and other virtual classes
 
end extern                  ' revert to internal function mode
 
 