PDA

Click to See Complete Forum and Search --> : What exactly is a precompiled header?


Wynd
Jun 5th, 2001, 06:47 PM
nt

Dillinger4
Jun 5th, 2001, 07:34 PM
I think a precompiled header file is like importing classes
of an API into your program. like using #include <iostream.h>
for I/O in C++ or #include <afxwin.h> // MFC core and standard
components. From what i can gather being a Java programmer,
it's like using the import key word at the top of a .java file to import a specific class or a whole package into a file.

Heres some diffrences between C and Java just so you can take a look.

No preprocessor directives: Java treats constant definitions as
static final fields.

No global variables: Java defines an extreamly clean namespace.
Packages contain classes, classes contain methods and fields methods
contain variables. Thus there is no possibility for namespace
collisions.

Well-defined primative type sizes:
All the primative types in Java have well defined sizes. In C, the size
of int, short ,long types is platform dependent, which hampers portability.

Foward References: The Java compiler is smarter then the C compiler in
it allows methods to be invoked before being defined. This elimates the need
to define function in a header file before defining them in a program file, as
is done in C.

No method pointers: C allows the programmer to store the address of a function in a
variable and pass that function pointer to other functions. You cannot do this with
java methods but you can acheive similiar results by passing an object that implements
a particular interface.

Variable declarations anywhere: C only permitts local variable declarations to be at
the beginning of a method or block. Java allows the variable declarations anywhere
within a method or block. --NOTE-- most programmers perfer to keep variable
declarations at the top of a block or method however.

Garabage Collection: The Java Virtual Machine performs "Garabage Collection" or
deallocation of memory automatically. This elimates the need for Java programmers to
explictly manage memory used by all object and arrays. For instance an object is
eligible for garabage collection if there are nolonger any variables that hold a
refrence to that object.

Method overloading: Java programs can define multiple methods with the same name
as long as the methods have diffrent parameter lists.

Wynd
Jun 5th, 2001, 07:54 PM
Yeah, i have used Java before and I think it is a good language except it seems like you have to include the JRE in your installation file. (Ever java program that I have seen does)

Dillinger4
Jun 5th, 2001, 08:50 PM
I have yet to create an installation file or bundle any thing in a jar
file to be distributed but i would highly assume that you would want to include the JRE in there. As for C++ i think it's a pain in the $#@ plus not to mention prone to too many errors. Who wants to worry about deallocating memory and all of the other
hassels that go along with the language. Plus the complaition
process is crap. one little thing wrong in your program produces tons of complier errors.... C2504 undifined base class ,C4101 unrefrenced local variable, C1010 unexpected end of file. blah blah, blah.............

parksie
Jun 6th, 2001, 09:41 AM
Nobody's actually answered the question yet ;)

A precompiled header file (.pch) contains all the compiled type information from the headers that are included, so that the compiler doesn't compile the SAME HEADERs each file you go through. This is why for MFC you put everything in stdafx.h, and include that in every file. This allows the compiler to know it can use PCH for those files.

It doesn't do anything except speed up compilation by a factor of about 10 :D