In the "JPL Institutional Coding Standard for the C programming Language", I found following sentence just below the Rule 15 (page 14):
"This is consistent with the principle that the use of total functions is preferable over non-total functions.".
I haven't heard the "total functions" before. What is this? Could you give me some example of the total function?
Below is the link to the JPL document.
That's explained in the next sentence in the document:
A total function is setup to handle all possible input values, not just those parameter values that are expected when the software functions normally.
I think it's originally a mathematical term. A total function is one that has well defined behavior for all possible argument values.
An example of a non-total function is strlen()
, which has undefined behavior if its argument is a null pointer, or an invalid pointer, or a pointer into an array that has no null '\0'
character. (And there's no real way, at least in portable C, to make strlen()
detect and handle all possible invalid arguments.)
A total function, in the sense used in the document either returns a meaningful result for all possible inputs, or detects any invalid inputs and reports an error in some well defined manner.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments