Re: .h files
From: Chance (chance_nospam_at_cox.net)
Date: 09/05/04
- Next message: sam: "IDE on linux"
- Previous message: cristian: ".h files"
- In reply to: cristian: ".h files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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):
-- 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
>
>
- Next message: sam: "IDE on linux"
- Previous message: cristian: ".h files"
- In reply to: cristian: ".h files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|