By: David Intersimone
Abstract: C++Builder XE3 provides support for pre-compiling the header files used in your C++ applications
This is a copy of a blog post from David I's Sip from the Firehose blog. Click to blog post title below to see the original blog post and comments.
C++Builder XE3 provides support for pre-compiling the header files used in your C++ applications. Creating and using precompiled headers can do two major things for you: 1) it can reduce the compilation time of C++ files, 2) it can reduce the number of lines of code that the compiler must process (in some cases, by several orders of magnitude). The IDE automatically generates a PCH.h file for every new C++ project for any target platform (Mac OS X, 32-bit Windows, or 64-bit Windows). You can see the PCH.h file as a node in the Project Manager:
You do not have to use the PCH.h file that is generated for you, but if you want to use a precompiled header with your application, you should edit and use the PCH.h file. The compilers will automatically use the PCH.h file. Using a precompiled header file on 64-bit Windows is different from using precompiled headers with BCC32.
The 32-bit C++Builder compiler has always had the default behavior of generating precompiled headers for you, and this behavior is not changed. Now, however, you can tell BCC32 to use the PCH.h file shown in the Project Manager if you simply #include the PCH.h file (followed by #pragma hdrstop;) in each source file in your project. You should, of course, edit the contents of the PCH.h file to #include all the headers needed in your project.
Creating a Precompiled Header for the C++Builder 64-bit compiler
The following procedure shows how to use precompiled headers in your C++ 64-bit Windows applications. The 64-bit Windows compiler accepts only one header file per project. Following the steps below, you create the single header file and use it as a precompiled header for a source file, in a 64-bit C++ project.
Precompiled Header Files - Things to consider
When used indiscriminately, precompiled headers can actually increase compilation time. Watch out for the following potential issues:
Some headers are not good candidates to include in a precompiled header. Use the following guidelines to determine whether a header should be precompiled.
Precompiled headers can hide incorrect code. For example, a .cpp file that fails to explicitly include a needed header might compile with no errors when using a precompiled header that includes the missing header file but fail when the precompiled header is disabled. It’s a good idea to build without precompiled headers every once in a while to ensure that your source correctly includes all necessary headers.
C++ Precompiled Headers Project Options
In the IDE, you can use the Project > Options > C++ Compiler > Precompiled headers project options dialog box to set C++ Compiler Precompiled headers options. You can find additional details about the precompiled headers project options dialog box on the Embarcadero DocWiki athttp://docwiki.embarcadero.com/RADStudio/XE3/en/C%2B%2B_Compiler_Precompiled_Headers
The Precompiled Header Wizard is currently designed for use with 32-bit Windows C++. This wizard does not produce the format used by 64-bit Windows C++ at this time.
CodeRage 7 C++ Conference, December 10-12, 2012
The CodeRage 7 C++ conference starts next Monday, December 10, 2012 at 6am Pacific Standard Time (14:00 UTC). There are 3 days of C++ sessions including my special live, online conversation with Bjarne Stroustrup at 8am PST (16:00 UTC) on Monday. Some of the C++ sessions you won’t want to miss are included in my blog post on November 21 - http://blogs.embarcadero.com/davidi/2012/11/21/41993.
During the first 25 days of December leading up to Christmas, I will blog about the upcoming release of the C++Builder 64-bit compiler for Microsoft Windows and C++Builder XE3support for building VCL and FireMonkey 2 applications.
Free 30-day license of new C++Builder XE6! Develop for Windows, Mac, Android and iOS!
Click to download now!
More social media choices:
C++Builder on Google+
@RADtools on Twitter
Server Response from: ETNASC02