Macros

Chapter 1 - The Visual C++ Compiler, Version 6

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Important Compiler Features
The Visual C++ compiler package contains many useful enhancements, new features, and options. The following sections introduce you to these improvements and briefly explain their uses.
p-code
p-code (short for “packed code”) is geared toward optimizing code speed and size. p-code can significantly reduce a program’s size and execution speed by as much as 60 percent. Better yet, all of this is accomplished simply by turning on the specific compiler option. This means that any code written in C or C++ can be compiled either normally or with p-code.
This technology compiles an application’s source code into “interpreted object code,” which is a higher-level and more condensed representation of object code. The process is completed when a small interpreter module is linked into the application.
The most efficient use of this technology does require some expertise, however. Since the interpreter generates object code at run time, p-code runs more slowly than native object code. With careful use of the #pragma directive, an application can generate p-code for space-critical functions and switch back to generating native code for speed-critical functions.
The best candidates for p-code generation are those routines that deal with the user interface, and because many Windows applications spend 50 percent of their time handling the user interface, p-code provides the optimum performance characteristics.
Precompiled Headers and Types
Visual C++ places generic types, function prototypes, external references, and member function declarations in special files called header files. These header files contain many of the critical definitions needed by the multiple source files that are pulled together to create the executable version of your program. Portions of these header files are typically recompiled for every module that includes the header. Unfortunately, repeatedly compiling portions of code can cause the compiler to slow down.
Visual C++ speeds up the compile process by allowing you to precompile your header files. While the concept of precompiled headers isn’t new, the way that Microsoft has implemented the feature certainly is. Precompilation saves the state of an application’s compilation to a certain point and represents the relationship that is set up between the source file and the precompiled header. It is possible to create more than one precompiled header file per source file.
One of the best applications of this technology involves the development cycle of an application that has frequent code changes but not frequent base-class definitions. If the header file is precompiled, the compiler can concentrate its time on the changes in the source code. Precompiled headers also provide a compile-time boost for applications with headers that comprise large portions of code for a given module, as often happens with C++ programs.
The Visual C++ compiler assumes that the current state of the compiler environment is the same as when any precompiled headers were compiled. The compiler will issue a warning if it detects any inconsistencies. Such inconsistencies could arise from a change in memory models, a change in the state of defined constants, or the selection of different debugging or code-generation options.
Unlike many popular C++ compilers, the Microsoft C++ compiler does not restrict precompilation to header files. Since the process allows you to precompile a program up to a specified point, you can even precompile source code. This is extremely significant for C++ programs, which contain most of their member function definitions in header files. In general, precompilation is reserved for those portions of your program that are considered stable; it is designed to minimize the time needed to compile the parts of your program under development.
The Microsoft Foundation Class Library
Windows applications are easy to use; however, they are not as easy to develop. Many programmers get waylaid by having to master the use of hundreds of Windows API functions required to write Windows applications.
Microsoft’s solution to this steep learning curve is the object-oriented Foundation Classes library. The reusable C++ classes are much easier to master and use. The Microsoft Foundation Class (MFC) library takes full advantage of the data abstraction offered by C++, and its use simplifies Windows programming. Beginning programmers can use the classes in a “cookbook” fashion, and experienced C++ programmers can extend the classes or integrate them into their own class hierarchy.
The MFC library features classes for managing Windows objects and offers a number of general-purpose classes that can be used in both MS-DOS and Windows applications. For example, there are classes for creating and managing files, strings, time, persistent storage, and exception handling.
In effect, the Microsoft Foundation Class library represents virtually every Windows API feature and includes sophisticated code that streamlines message processing, diagnostics, and other details that are a normal part of all Windows applications. This logical combination and enhancement of Windows API functions has ten key advantages:
  The encapsulation of the Windows API is logical and complete The MFC library provides support for all of the frequently used Windows API functions, including windowing functions, messages, controls, menus, dialog boxes, GDI (graphics device interface) objects (fonts, brushes, pens, and bitmaps), object linking, and the multiple document interface (MDI).
  The MFC functions are easy to learn Microsoft has made a concerted effort to keep the names of the MFC functions and associated parameters as similar as possible to their Windows API parent classes. This minimizes the confusion for experienced Windows programmers wanting to take advantage of the simplified MFC platform. It also makes it very easy for a beginning Windows programmer to grow into the superset of Windows API functions when they are ready or when the application requires it.
  The C++ code is more efficient An application will consume only a little extra RAM when using the classes in the MFC library. The execution speed of an MFC application is almost identical to that of the same application written in C using the standard Windows API.
  The MFC library offers automatic message handling The Microsoft Foundation Class library eliminates one frequent source of programming errors, the Windows API message loop. The MFC classes are designed to automatically handle every one of the Windows messages. Instead of using the standard switch case statements, each Window message is mapped directly to a member function, which takes the appropriate action.
  The MFC library allows self-diagnostics Incorporated into the MFC library is the ability to perform self-diagnostics. This means that you can dump information about various objects to a file and validate an object’s member variables, all in an easily understood format.
  The MFC library incorporates a robust architecture Anticipating the much-needed ANSI C throw/catch standard, the Microsoft Foundation Class library already incorporates an extensive exception-handling architecture. This allows an MFC object to eloquently recover from standard error conditions such as “out of memory” errors, invalid option selection, and file or resource loading problems. Every component of the architecture is upward compatible with the proposed ANSI C recommendations.
  The MFC library offers dynamic object typing This extremely powerful feature delays the typing of a dynamically allocated object until run time. This allows you to manipulate an object without having to worry about its underlying data type. Because information about the object type is returned at run time, the programmer is freed from one additional level of detail.
  The MFC library can harmoniously coexist with C-based Windows applications The most important feature of the Microsoft Foundation Class library is its ability to coexist with C-based Windows applications that use the Windows API. Programmers can use a combination of MFC classes and Windows API calls within the same program. This allows an MFC application to easily evolve into true C++ object-oriented code as experience or demand requires. This transparent environment is possible because of the common naming conventions between the two architectures. This means that MFC headers, types, and global definitions do not conflict with Windows API names. Transparent memory management is another key component to this successful relationship.
  The MFC library can be used with MS-DOS The Microsoft Foundation Class library was designed specifically for developing Windows applications. However, many of the classes provide frequently needed objects used for file I/O and string manipulation. For this reason, these general-purpose classes can be used by both Windows and MS-DOS developers.
  The MFC library and wizards The Class and Control Wizards only create code compatible with the MFC. These dynamic program developers are a must when developing OLE applications.
Function Inlining
The Microsoft Visual C++ Compiler supports complete function inlining. This means that functions of any type or combination of instructions can be expanded inline. Many popular C++ compilers restrict inlining to certain types of statements or expressions—for example, the inline option would be ignored by any function that contains a switch, while, or for statement. The Visual C++ compiler allows you to inline your most speed-critical routines (including seldom-used class member functions or constructors) without restricting their content. This option is set from the Project menu by selecting Settings..., then the C/C++ folder, and finally Optimizations from the Category list.

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

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