Results 1 to 5 of 5

Thread: What exactly is a precompiled header?

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    What exactly is a precompiled header?

    nt
    Alcohol & calculus don't mix.
    Never drink & derive.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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)
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.............

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width