Re: .h files

From: Chance (chance_nospam_at_cox.net)
Date: 09/05/04


Date: Sun, 05 Sep 2004 15:44:41 -0500


Having header (.h) files allows the ability to separate the interface
from the code -- eg, create libraries. A header file gives the
necessary information needed to use precompiled object files.

Think about it: how would it be to compile a "Hello, World" program and
  have to compile printf's dependencies -- meaning every single function
.. down to the OS's kernel interface?

These interfaces allow for some general cool stuff, not the least of the
"stuff" being piecewise program compilation. When you're working with
large programs, you don't have to re-compile every single source file ..
  you simply re-compile what you're working on to object files(possibly
anything that depends on what you're working on) .. and then link them
together in one fatal swoop.

These interfaces also allow the operating system to do some rather
interesting things. The Linux kernel, for example. uses common code for
functions. From what I understand, every time a 'printf' or 'cout' or
what have you is executed, the actual, physical code that is executed is
the same exact code (in the same exact _location_) that every other
printf call uses. Therefore you don't need 77,000 copies of printf
sitting around in RAM - you simply have one, common, binary printf and
everybody knows how to interface with it because of its header file.

The book "Thinking in C++, Vol. 1" by Bruce Eckel makes the use of
header files painfully clear (start from the beginning, its a great
reference):

http://www.mindview.net/

  -- Chance

cristian wrote:
> hi...
>
> I 'm trying to learn some game programming now from a book... and there's
> alot of .h files. (I assume that there are lot's of .h files in other typ of
> programming too, that's the reason for posting it here... only that I come
> in contact with it in game programming).
>
> My question is... why have .h files??? and I'm not lookig for a "to put
> parts of the program in other files" type of answer... I know how to use
> them... but why did someone feel that we needed .h files from the start... I
> need someone to explain them so I understand why they exist and how and when
> I should use (create) them.
>
> and also... why have a .h file and a .cpp file for a class... why not just
> put all the code in the .h file...?
>
>
> Another thought I have is the .dll files... now I've newer worked with them
> at all so I dont really know much of them but arent the kinda like .h files?
>
> mvh. cristian D
>
>



Relevant Pages

  • Re: Why localize structures in this case.
    ... pointer to an object of the other class/ struct type. ... Methods are supposed to provide an interface to some ... overhead of stuff like referring to all data members through an extra ... to just put an abstract class in the header file as the interface ...
    (comp.unix.programmer)
  • HOWTO: Create a new ATL VC++ class for a MAPI Address Book Provider
    ... If you want to develop a MAPI Address Book Provider ... How to make an interface inherite from another interface using ATL ... paste them into the new header file ABProvider.h into the class ...
    (microsoft.public.win32.programmer.messaging)
  • HOWTO: Create a new ATL VC++ class for a MAPI Address Book Provider
    ... If you want to develop a MAPI Address Book Provider ... How to make an interface inherite from another interface using ATL ... paste them into the new header file ABProvider.h into the class ...
    (microsoft.public.win32.programmer.messaging)
  • Re: C++ header file
    ... There is no reason not to do that, in fact the compiler does allow that. ... the interface and would have to compile the whole code, ... there must be a header file map to it. ...
    (microsoft.public.vc.language)
  • Re: If (global header files are bad) then ??
    ... the wrong header file is read in the wrong context. ... The next solution to this is to give the client a single header file and a .lib file which ... statically-linked MFC libraries vs. the shared MFC DLL library. ... Note however that all of these have one common theme: a single .h file as the interface ...
    (microsoft.public.vc.mfc)