Arguments and function results

Use the following conventions for function arguments and function results (at Taligent, any deviation requires an architect's approval). Additionally, for information about when to pass a reference as opposed to a pointer, see "Use references for a one-time reference" on page 72.

Here are some rules for what a function should return:

Return results by value only when there is no need for polymorphism and when the size of the type isn't too large, because the result will be copied. Remember, if you return an object by value, one of its constructors will be called (see the ISO/ANSI C++ draft standard for details on function result semantics).

Use a pointer to return an alias from a function. If storage is being allocated on behalf of the caller, the function name should start with Create... or Copy... (see "Name conventions" on page 58).

Never return references from functions (or at least check with your architect first). It isn't possible to bound the reference's scope of use (unlike when a reference is passed in, in which case it is guaranteed not to be used after the function call). If you must do this, return a pointer (but see "Avoid returning pointers without allocation" on page 71).


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker