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 a function with no arguments that returns an integer.
int noArgs();
 
/// Declare a function with no arguments that returns an integer.
int twoArgs(int a, int b);
 
/// Parameter names are optional in a prototype definition.
int twoArgs2(int, int);
 
/// An ellipsis can be used to declare a function that accepts
/// C-style varargs.
int anyArgs(...);
 
/// One mandatory integer argument followed by C-style varargs.
int atLeastOneArg(int, ...);
 
/// Declare a function that accepts any number of integers.
void anyInts(int[] a...);
 
/// Declare a function that accepts D-style varargs.
void anyArgs2(TArgs...)(TArgs args);
 
/// Declare a function that accepts two or more D-style varargs.
void anyArgs3(TArgs...)(TArgs args) if (TArgs.length > 2);
 
/// Currently D doesn't support named arguments.
 
/// One implementation.
int twoArgs(int a, int b) {
    return a + b;
}
 
interface SomeInterface {
    void foo();
    void foo(int, int);
 
    // Varargs
    void foo(...); // C-style.
    void foo(int[] a...);
    void bar(T...)(T args); // D-style.
 
    // Optional arguments are only supported if a default is provided,
    // the default arg(s) has/have to be at the end of the args list.
    void foo(int a, int b = 10);
}
 
void main() {}