Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Professional C++ [eng].pdf
Скачиваний:
284
Добавлен:
16.08.2013
Размер:
11.09 Mб
Скачать

Developing Cross-Platform and Cross-Language Applications

warning: ISO C++ forbids variable-size array ‘myStackArray’

The C++ specification allows for a certain type of compiler-defined language extension through the #pragma mechanism. #pragma is a precompiler directive whose behavior is defined by the implementation. If the implementation does not understand the directive, it simply ignores it. For example, some compilers allow the programmer to turn compiler warnings off temporarily with #pragma. However, this behavior is compiler-dependent and you should not rely on it.

Library Implementations

Most likely, your compiler includes an implementation of the C++ standard library, including the standard template library. Since the STL is written in C++, however, you aren’t required to use the one that came bundled with your compiler. You could use a third-party STL that has been optimized for speed or you could even write your own.

Of course, STL implementers face the same problem that compiler writers face — the standard is subject to interpretation. In addition, certain implementations may make tradeoffs that are incompatible with your needs. For example, some implementations may increase their single-processor performance profile by giving up multiple-processor support. Others may be tuned especially for multiple processors.

When working with an STL implementation, or indeed any third-party library, it is important to consider the tradeoffs that the designer made during development. If the library is open source, you may be able to find a current list of open issues or a bug database. Chapter 4 contains a more detailed discussion of the issues involved in using libraries.

Platform-Specific Features

C++ is a great general-purpose language. With the addition of the Standard Library, the language is packed full of so many features that a casual programmer could happily code in C++ for years without going beyond what is built in. However, professional programs require facilities that C++ does not provide. This section lists several important features that are provided by the platform, not by the C++ language.

Graphical user interfaces. Most commercial programs today run on an operating system that has a graphical user interface, containing such elements as clickable buttons, movable windows, and hierarchical menus. C++, like the C language, has no notion of these elements. To write a graphical application in C++, you need to use platform-specific libraries that allow you to draw windows, accept input through the mouse, and perform other graphical tasks. Chapter 25 describes object-oriented graphical frameworks as one way that platforms provide this functionality.

Networking. The Internet has changed the way we write applications. These days, it’s not uncommon for an application to check for updates through the Web or for a game to provide a networked multiplayer mode. C++ does not provide a mechanism for networking, though several standard libraries exist. The most common means of writing networking software is through an abstraction called sockets. A socket library implementation can be found on most platforms and it provides a simple procedure-oriented way to transfer data over a network. Some platforms support a streams-based networking system that operates like I/O streams in C++.

OS Events and application interaction. In pure C++ code, there is little interaction with the surrounding operating system and other applications. The command-line arguments are about all

493