Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   question regarding header files (http://www.velocityreviews.com/forums/t291077-question-regarding-header-files.html)

siddharth_jain_1@rediffmail.com 05-16-2005 02:06 PM

question regarding header files
 
Hello,

1) what do header files contain exactly?
Do they just contain the variable declarations, typedefs and
function prototypes?

2) taking the example of iostream.h: it contains the prototyoes of
various functions. which file has the actual code of these functions?


3) If I build my own header file (header.h) which includes some
function prototypes and I have another file (program.c) that has the
actual code for these functions, when I go to use those in another
program. If i #include "myheader.h" in my new file (project.c) will it
then know to look in code.c for the function?

4) Could someone please guide me to a good link from where I can read
about the usage of header files/


Thanks,

Siddharth Jain


Victor Bazarov 05-16-2005 02:16 PM

Re: question regarding header files
 
siddharth_jain_1@rediffmail.com wrote:
> 1) what do header files contain exactly?
> Do they just contain the variable declarations, typedefs and
> function prototypes?


They contain anything that you deem necessary to share between compilation
units. Headers are usually created to be included in more than one module
to be compiled.

> 2) taking the example of iostream.h:


BTW, there is no such header. I will assume we're talking <iostream>.
Also, you should know that _standard_ headers are not necessarily files.
Just so we're clear on that.

> it contains the prototyoes of
> various functions. which file has the actual code of these functions?


That's specific to the implementation. If the compiler vendor supplied
you with the source code to their implementation of the Standard library,
then the actual code is there somewhere. If the vendor didn't provide
the source code, then the actual code is on the vendor's computers and
you only get to see the declarations.

> 3) If I build my own header file (header.h) which includes some
> function prototypes and I have another file (program.c) that has the
> actual code for these functions, when I go to use those in another
> program. If i #include "myheader.h" in my new file (project.c) will it
> then know to look in code.c for the function?


No, it won't. You will need to compile 'code.c' separately and add it to
the command line of the linker so that the object code is linked into the
final program.

> 4) Could someone please guide me to a good link from where I can read
> about the usage of header files/


www.google.com

V

eeykay@gmail.com 05-16-2005 02:17 PM

Re: question regarding header files
 
STLs usaully provides implementation also in the header files. Your
point 1. is correct. Regarding your point 3, I assume code.c includes
"myheader.h". So, the compiler compiles it to an code.obj file, which
the linker uses to link with your project.obj, to produce the final
program. You should look for how c++ program compiles to generate an
output for more in-depth details. Writing your own makefile will also
help understanding these things.
-EK


osmium 05-16-2005 02:36 PM

Re: question regarding header files
 
<siddharth_jain_1@rediffmail.com> wrote:


> 1) what do header files contain exactly?
> Do they just contain the variable declarations, typedefs and
> function prototypes?


They also usually contain the actual code (the function definition) for
templated functions.




All times are GMT. The time now is 09:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.