Page #26 (Separating Interface from Implementation)

< BACK  NEXT >
[oR]

Common Aspects of C++ Language

The following aspects of the C++ language can be assumed to be implemented uniformly across all compilers. Many of these aspects may require the use of conditionally compiled type definitions, pragmas, or other compiler directives.

  • Run-time representation of basic data types is uniform: Basic data types such as int, char, float, double, etc., can be represented in the same way across all C++ compilers.

  • Run-time representation of composite data type is uniform: Composite data types such as C-style structs can be represented in the same way across all C++ compilers. Sometimes compiler pragmas may have to be used to pack the structs in the same way.

  • Argument passing order is uniform: All C++ compilers can be forced to pass function arguments for any specific function in exactly the same order (left to right, right to left).

  • Argument passing convention is uniform: All C++ compilers can be forced to pass function arguments by value. In fact, this is the default behavior for all the compilers.

  • Stack-maintenance responsibility is uniform: The responsibility of cleaning the stack, that is, popping the arguments from the stack, can be conditionally specified for the called function or the calling function.

  • Case-translation convention: The linker can be forced to resolve symbolic references as case-sensitive or case-insensitive.

  • No name mangling for C-Style functions: By declaring a C-Style function as extern "C", the compiler s name-mangling mechanism for the specific function can be turned off.

  • Implementation of virtual function is uniform: On any given platform, the machine language code generated when a virtual function is called is equivalent for all compilers. This is perhaps the most important assumption made so far and needs further discussion. The next section discusses this aspect in detail.

Many of these aspects can be controlled by just one compiler directive. For example, all WIN32 APIs are defined using the WINAPI preprocessor symbol. This symbol maps to _stdcall directive with the Microsoft compiler on the Intel platform. Table 1.1 summarizes the implication of this directive.

Table 1.1. Implementation of _stdcall Compiler Directive

Element

Implementation

Argument-passing order

Right to left

Argument-passing convention

By value, unless a pointer or reference type is passed

Stack-maintenance responsibility

Called function pops its own arguments from the stack

Case-translation convention

None

Let s look at how the compiler uses the definition of a class in generating machine language code. This will provide some insight on how to achieve compiler independence using virtual functions.


< BACK  NEXT >


COM+ Programming. A Practical Guide Using Visual C++ and ATL
COM+ Programming. A Practical Guide Using Visual C++ and ATL
ISBN: 130886742
EAN: N/A
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net