Thread: .cpp and .h

  1. #31
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Why doesn't the compiler do that for every header file? . . . .

    It could use the timestamp to determine if the header file has been modified since it was last opened. Though only rather complex build processes would modify header files in this way, I should imagine.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't know. Seems kind of silly.
    But Microsoft aren't known for making sense.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Timestamps? Huh? Do you expect headers to change during a compilation?

    Nah, the "open only once" doesn't carry across compiles. It's more about this situation:
    Code:
    // a.h
    // stuff
    
    // b.h
    #include "a.h"
    
    // c.h
    #include "a.h"
    
    // main.cpp
    #include "b.h"
    #include "c.h"
    If the headers are protected by the typical guards, then the MS compiler will open a.h twice, only to discover the second time that there's nothing there to read. With pragma once, the compiler puts the file name into a list which it looks at before doing the next include - if the file's in there, it won't even be opened. Since opening a file can take quite some time, this can speed up compilation.

    Of course, other compilers are way ahead of MS's and simply recognize the include guard pattern. If there is no functional token outside the #ifndef SYMBOL #define SYMBOL ... #endif sequence, the compiler puts the file into the blacklist after including it. Same benefit, but no programmer interaction or non-standard pragma needed.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get .cpp and .h files to communicate...
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2008, 12:45 AM
  2. .cpp and .h files - organization
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 01-12-2006, 11:40 PM
  3. Why Declare in .H but Define in .CPP ?
    By Krak in forum C++ Programming
    Replies: 10
    Last Post: 07-30-2005, 12:36 AM
  4. placement of (.h) and (.cpp) files..!?
    By matheo917 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 06:37 PM
  5. Class files (.h and .cpp
    By Todd in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 03:07 PM