**2.4 Interface casting**

General casting methods of C++ such as static\_cast and dynamic\_cast cannot be used among objects created by different types of compilers. Therefore, methods that can cast BiCOMC objects are necessary regardless of a type of compilers used. **Figure 4** shows an algorithm for casting BiCOMC objects to other interfaces.

The casting algorithm gets virtual function tables using two parameters of obj and tgtTable. The algorithm compares the tables of obj with the tables of the target interface in order to check whether or not two interfaces are compatible. NULL is returned if two interfaces are not compatible each other. The seventh, tenth, and

#### *How to Keep the Binary Compatibility of C++ Based Objects DOI: http://dx.doi.org/10.5772/intechopen.77383*

#### **Figure 4.**

*Algorithm for interface casting.*

forty-second lines in **Figure 4** are for processing of multiple inheritance. Lines 21–24 check hash values to test the names of interfaces and inheritance relationships. That is, lines 21–24 compare the hash values and detect whether they are compatible by detecting whether a new interface is added or a different interface name exists. Lines 25–37 compare subhash values, and two interfaces are considered as compatible interfaces if the values are the same. If they are different, it examines method signatures of interface information to check compatibility. An example of interface casting is shown in **Figure 6**.
