Prefix header
Encyclopedia
In computer programming
, a prefix header
is a feature found in some C
or C++
compilers used to simplify code and/or to reduce compilation time.
and C++
programming languages, a header file
is a file
whose text is automatically included in another source file by the compiler
, usually by the use of compiler directives at the beginning of the source file. A prefix header differs from a normal header file in that it is automatically included at the beginning of every source file by the compiler, without the use of any compiler directives.
Prefix headers are usually pre-compiled
in order to reduce compilation times.
, the Xcode
build system generates prefix headers automatically for new projects. A new Cocoa
project, for instance, gets a prefix header that looks like this:
As a result, it is unnecessary to explicitly include any of the above files in any Objective-C
code in the program, although doing so is harmless, in the case of Objective-C because of the semantics of the
s.
Similar prefix headers are generated for other types of project.
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...
, a prefix header
Header
Header may refer to: Computers and engineering* Header , supplemental data at the beginning of a data block** E-mail header** HTTP header* Header file, a text file used in computer programming...
is a feature found in some C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
or C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
compilers used to simplify code and/or to reduce compilation time.
Overview
In the CC (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
programming languages, a header file
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...
is a file
Computer file
A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage. A file is durable in the sense that it remains available for programs to use after the current program has finished...
whose text is automatically included in another source file by the compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
, usually by the use of compiler directives at the beginning of the source file. A prefix header differs from a normal header file in that it is automatically included at the beginning of every source file by the compiler, without the use of any compiler directives.
Prefix headers are usually pre-compiled
Precompiled header
In computer programming, a precompiled header is a technique used by some C or C++ compilers to reduce compilation time.-Overview:In the C and C++ programming languages, a header file is a file whose text may be automatically included in another source file by the C preprocessor by the use of a...
in order to reduce compilation times.
Example
On Mac OS XMac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
, the Xcode
Xcode
Xcode is a suite of tools, developed by Apple, for developing software for Mac OS X and iOS. Xcode 4.2, the latest major version, is available on the Mac App Store for free for Mac OS X 10.7 , and on the Apple Developer Connection website for free to registered developers Xcode is a suite of tools,...
build system generates prefix headers automatically for new projects. A new Cocoa
Cocoa (API)
Cocoa is Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and...
project, for instance, gets a prefix header that looks like this:
As a result, it is unnecessary to explicitly include any of the above files in any Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...
code in the program, although doing so is harmless, in the case of Objective-C because of the semantics of the
#import
directive, but more generally with #include
because of the use of include guardInclude guard
In the C and C++ programming languages, an #include guard, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the #include directive...
s.
Similar prefix headers are generated for other types of project.