|
Tools BCC CHMOD CL COFF2OMF COFFIMPLIB DMC DIFF DIFFDIR DUMP DUMPOBJ DUMPEXE EXE2BIN FLPYIMG GREP HC IMPLIB LIB LIBUNRES MAKE MAKEDEP ME OBJ2ASM PATCHOBJ RC RCC SC SHELL SMAKE TOUCH UNMANGLE WHEREIS Compiling Compiling Code C Implementation C++ Implementation Language Extensions Mixing Languages Assembly Language Inline Assembler Optimizing Code Numerics Programming Regular Expressions Acrtused Pragmas Precompiled Headers Predefined Macros Warning Messages Error Messages Runtime Messages Linking Optlink Switches Module Definition Files Operation and Design Error Messages Win32 Programming Win32 Programming DOS and Win16 Programming Memory Models 16 Bit Pointer Types and Type Modifiers Handle Pointers DOS DOS 32 (DOSX) Win16 Win16 DLLs Win16 Prolog/Epilog Virtual Memory For 640Kb DOS C/C++ Extensions Contract Programming __debug statement __debug declaration Dynamic Profiling Embedding C in HTML Porting to DMC++ Switching to DMC++ from Microsoft from Borland Porting Guide |
Precompiled HeadersIf your program uses a large header file or numerous small headers, the compiler spends considerable time compiling the same code over and over again. To save compile time, precompile a header file; the compiler can load a precompiled header faster than it can a text header file. The compiler includes a precompiled header only once in a file, regardless of how many #include statements for it appear.How the compiler precompiles a headerA precompiled header consists of the header file's global symbol table and any macros defined by the header. A header intended for precompilation should, therefore, contain only declarations and no definitions.For example, the following declarations are appropriate for use in precompiled headers:
extern int abc;
int foo(int x);
inline void g(x) { foo(x); } // inline function definition
#define MACRO(x) asdf(x)
These will not work:
int def = 3; // a definition
void g(x) { foo(x); } // function definition
Precompiled header optionsThese switches to SC control precompiled headers. Corresponding IDDE options are in the Header Files subpage on the Build page of the IDDE's Project Settings dialog box.
#include the precompiled header in the source as you normally would. For example, to use a precompiled version of stdio.h in a program, write:
#include <stdio.h>
main()
{
printf("hello world\n");
}
The program's makefile must precompile the header file and include
the precompiled header in the list of dependencies for all the source
files that #include it. For example, this is the makefile for the
hello world program:
stdio.sym : stdio.h makefile sc -HF stdio.h hello.exe : hello.c stdio.sym sc -H helloThe first two lines are for the precompiled header. The name of the precompiled header is the same as the text header, except it ends in .sym instead of .h. The sc -HF command precompiles the header file, creates a .sym file and places it in the current directory. The precompiled header depends not only on the text header file, but also on the program's makefile. This is because changes in the makefile, such as using a different memory model or target CPU, change how the compiler precompiles the header. The last two lines above are for the program's source file. The executable file is dependent not only on its source file, but also on the precompiled header. The -H option tells the compiler that when it looks for a header file, it should first look in the current directory for .sym files. Using a project precompiled headerIf many source files #include the same files, you might want to create a project precompiled header that #includes several text header files.For example, if the files in the project all #include stdio.h, string.h and myglobals.h, create a project header file project.h that contains just these lines: #include <stdio.h> #include <string.h> #include "myglobals.h"Precompile project.h with this command: sc -HF project.hThen compile them with the -H and -HI options: sc file1 file2 file3 -HIproject.h -H "Automatic" Precompiled Headers (-HX)Using -HX improves compile times for most programs. Instances where this might not be the case include:
Using a fast disk with a precompiled headerTo make a precompiled header file even faster, place it on the fastest disk drive in your system. To let the compiler know where the precompiled file is, make some changes in the makefile. First, precompile the header file with -HF to specify where to place it. Then, use -HD to set the path to read the precompiled header.For example, if the fastest disk is drive e, the makefile for the hello world program would be: TMP=e: stdio.sym : stdio.h makefile sc -HF stdio stdio.h hello.exe : hello.c stdio.sym sc -HD helloor, with automatic precompiled headers: TMP=e: hello.exe : hello.c sc -HD -HX hello Tips For Precompiled HeadersTo make the best use of precompiled headers, follow these rules:
|