Protocol Implementation > Implementing Test Run > Code the API Functions > Declare the Functions > Argument Lists |
The SDK supports two approaches to declaring function argument lists:
using named arguments (recommended)
Named arguments have a <key>=<value> format. An argument key can only be used once in a single function invocation.
The function prototype has a variable-length parameter list. The step name is always the first argument and is positional. All other arguments are part of the variable-length list. For example:
int my_function(const char * stepname, ... );
The actual argument list for a call to a function using named arguments must end with the LAST marker. For example:
my_function("thisStep","Arg1=London","Arg2=York", LAST);
Functions declared with positional arguments more difficult to read and understand. Moreover, such a function cannot be extended without breaking compatibility with existing scripts because ANSI C does not support default values. Therefore, you cannot add a formal parameter and assign a default value to support existing scripts.
The usual approach to extending APIs with positional arguments is to create a new version of myMethod(a,b,c) called myMethodEx(a,b,c,d). This technique is inelegant and breaks down quickly if the API is extended several times in different versions.
Using named arguments results in scripts that are easier to read and maintain in extendable APIs. Utility functions for handling named arguments are provided in the SDK.