15. Formal Arguments

Formal Arguments are the argument definitions defined by the function definition.

In most cases we do not modify the contents of formal arguments.

While technically they can be modified, since they are copies of the original values on the stack, when it comes to passing pointers, the semantics of this can get confusing and thereby opens the door to difficult-to-find bugs. Thus, this Coding Standard is both a matter of style and code clarity, and a technical point of safety against future problems. Exceptions are permitted where it lowers CPU overhead (because it costs CPU time to copy the value from the argument to a local variable, e.g. for a short function that may be in the middle of a tight loop used hundreds or thousands of times) and does not hinder the ease of reading and understanding the source code.

Formal argument variables are usually prefixed with an ‘a’ scope prefix so it remains clear what is going on and that it is intentional. For these exceptions, sometimes formal arguments have a storage class of register to further reduce CPU overhead.

Example:

int     hm_math_ffs16(register int16_t ai16Val);