Parameter passing between C++ and Objective-C methods

Two methods of parameter passing are supported: the standard method and parameter passing using the Standard-C stdarg mechanism [6]. The second method supports an arbitrary number of arguments to be passed to C++ method. Figure 7 shows the two supported parameter-passing methods and examples. Figure 8 shows the implementation details of the required interfacing functions to support these two types of parameter passing.

To aid users in extracting arbitrary number of arguments from the va_list structure (through the use of Standard-C va_start, va_arg and va_end macros), a supporting C++ class called objc_t and its corresponding “>>” overloaded output stream operator have been implemented and stored in the in the supporting file ObjCsupport.h. An example of the usage is shown in Figure 7 in the user C++ implementation of the sumN_x1 member method (in this case, to sum a list of three real numbers).

Figure 7: Supported parameter passing methods and examples.
\begin{figure}\begin{description}
\item[Standard parameter passing method:]\mbox...
...>> x2 >> x3, return x1 + x2 + x3; }\end{verbatim}
\end{description}
\end{figure}

Figure 8: Supporting interfacing functions needed.
\begin{figure}\begin{description}
\item[Objective-C interface functions generate...
... return obj->sumN_x1(x1, buffer); }\end{verbatim}
\end{description}
\end{figure}

Figure 9 shows the algorithm used to translate a C++ function prototype to its Objective-C equivalent. The translation of the C++ function argument string to Objective-C equivalent is defined in the writeobjc action in the Classdesc's Objective-C base action definition file writeobjc_base.h.

Figure 9: C++ $\leftrightarrow $ Objective-C function prototype translation algorithm
\begin{figure}\begin{verbatim}Given C++ function prototype:
Cpp-return-type f...
...1 to argn
construct standard ObjC-type-argument-list\end{verbatim}
\end{figure}

To support the use of C++ only member-methods in the user model, following member functions will not be translated to its Objective-C equivalent: argument-list contains any C++ objects (such as vector) or function-name that contain “cpp_” prefix.