Function prototypes and headers

Every function in AROS must have a full ANSI C prototype. Prototypes should be collected in in one header per file if it is needed by only a few files (no need to recompile the whole project if you change a function which used only once), in one header per directory if it's a commonly used function in that directory or in one header per logical group (ie. one header for all functions in a library).

The function header (ie. the comment before the function) must be of a special format because the AutoDocs are generated from it. Here is an example for it (from AROS/exec/addhead.c):


\begin{example}
/***************************************************************...
...***************************************************************/
{
\end{example}

As you can see, comments are used to merge the function prototype and the header into one.

NAME This field contains all neccessary prototypes to use the function from the user point of view and the name of the function in a |AROS_LH*()| macro (Library Header). These macros are used to make the same code work on different kind of hardwares. The name of the macro depends on the amount of parameters and whether the function needs the library base. |AddHead()| does not and therefore an "I" is appended to the macros name. If it need the library base (like |AddTask()|), then the "I" is omitted.

If the function is not part of a shared library and it's arguments must be passed in certain registers (eg. callback hooks), you must use |AROS_UFH*()| macros (User Function Header) instead of |AROS_LH*()|. Append the number of arguments to this macro. Since it has never a base, the field LOCATION must be omitted and it's not neccessary to append the "I" to the macros name. An example for a callback hook |foo()| would be:


\begin{example}
AROS_UFH3(ULONG, foo,
AROS_UFHA(struct Hook, hook, A0),
AROS_UFHA(APTR, obj, A2),
AROS_UFHA(APTR, param, A1)
)
\end{example}

(note that the registers need not have a particular order).

If the function is not part of a shared library and it's arguments need not be in specific registers, you need no |AROS_*H*()| macros:


\begin{example}
/***************************************************************...
...*****************************************************************/
\end{example}

SYNOPSIS This field contains all arguments of the function one by one in |AROS_LHA()| macros (Library Header Argument). This macro makes sure the respective argument is put in the right CPU register when the function is called (if possible and neccessary). The first argument for the macro is the type of the parameter followed by the name of the parameter and the register the parameter is expected in. Valid names for registers are D0, D1, D2 upto D7 and A0 upto A6.

If the function is not part of a library but the arguments must be passed to it in registers, then use |AROS_UFHA()| macros (User Function Header Argument) which take the same parameters as the |AROS_LHA()| macros. Don't forget the closing parenthese for the AROS_UFC

If the function is not part of a library and the arguments need not be passed in registers, no macros are neccessary.

LOCATION This field is neccessary for shared libraries only. It contains the last four parameters for the |AROS_LH*()| macro which are the type of the library, the name of the variable, in which the function expects the library base, the offset of the function in the jumptable (the first vector has 1 and the first vector which may be used by a function is 5) and the name of the library.

FUNCTION This field contains a description of the function.

INPUTS This field contains a list of all parameters of the form "name - description" or "name, name, name - description". The description should tell what the parameter is and what values can be passed to it. There is no point in explaining the parameter twice in FUNCTION and here. If the function has no parameters, say "None." here.

RESULT What the function passes back. This includes return values and values passed in arguments of the function. If the function may fail, you should explain what it returns on failure and why it might fail.

NOTES Important things the user must know or take into account.

EXAMPLE This field should contain a small or fully featured example. A good way to present an example is to write some code which tests the function, put it into |#ifdef TEST| somewhere in the file and put a "See below." here. If you need comments in the code, you have two ways for this. If you need only short one-line comments, use C++ style (|// comment|). Everything from the |//| to the end if the line is the comment. If you need more comment, then you can end the comment after the |EXAMPLE| and use |#ifdef EXAMPLE| to mask the example out:


\begin{example}
EXAMPLE */
...

Don't use |#ifdef EXAMPLE| if you have a fully featured example (ie. one which can be compiled without errors).

BUGS This field contains a list of known bugs.

SEE ALSO This field contains a list of other functions and documents which might be of interest. This includes function which you need to initialize, create or destroy an object necessary for this function, functions which do similar and opposite things on the main object.

For example, |SetAttrs()| should contain functions here which can create, destroy and manipulate BOOPSI objects but not taglists.

INTERNALS This field should contain information for other developers which are irrelevant to the user, for example an explanation of the algorithm of the function or dependencies.

HISTORY This field should contain a brief history of changes. The format is date (DD-MM-YY), acronym (one word) and description.