Header files.

Oct 12, 2008 at 2:45am
I'm confuse on what .h files do and why you need. I'm guessing its where you put in all the libraries that you used. If you can tell me if I'm right or wrong that would be great.
Oct 12, 2008 at 3:42am
I am not sure either. I know .h stands for header files. Past that I dont know anything.

I use .h for all my funtions. It helps me keep them apart from my main funtion. But I dont think it really matter the compiler. I have used .seeJackRun and .jakAndJill just to see if it would use the file. I also tryed using no extention. All three worked just fine. But it can get confusing to the user.
Oct 12, 2008 at 3:58am
Hi Guy,

The .h is a suffix given to the certain libraries or header files in C. To keep the compatibility with those libraries, C++ allow you to use either the suffix .h or the prefix c before the name of the library.

1
2
3
4
5
6
7
8
 // This is C++ code
 
 #include <cstdio>                // Nothing unusual in #include line
 
 int main()
 {
   std::printf("Hello world\n");  // Nothing unusual in the call either
   ...


1
2
3
4
5
6
7
8
9
 /* This is C code that I'm compiling using a C++ compiler */
 
 #include <stdio.h>          /* Nothing unusual in #include line */
 
 int main()
 {
   printf("Hello world\n");  /* Nothing unusual in the call either */
   ...
 } 


Hope it helps you.
Last edited on Oct 12, 2008 at 3:59am
Oct 12, 2008 at 9:27am
The .h is a suffix given to the certain libraries or header files in C.

Partially correct.

.h - is extension of C header file
But compiler doesn't actually care about your file extensions and it is still common to use header files with extension ".h".

Header files are usually used for class and/or function declarations, for template classes and/or functions and for inline function definitions.
Last edited on Oct 12, 2008 at 9:30am
Oct 12, 2008 at 11:29am
Sometimes .h is required. My compliler requires .h when I'm trying to include 'curses' and 'config'.
Oct 12, 2008 at 11:50am
The most important thing about using header file is Encapsulation, and this is also one of the most important features of Object-Oriented Programming.

Using header file to save the declarations of class (only declarations, no definition of functions) and the variables that you wish to use in different source files.

Once you provide your class to the users, you can only provide the header file(including declarations of class, infomation about how to use this class and etc.) and the .obj file(the source code of .cpp file has been compiled and translated to machine language, the customer can not read your source code from .obj file, but your computer can understand it).

Because of that, your source code is totally safe, and the users can not read and change your source code, they can only use it.
Last edited on Oct 12, 2008 at 11:57am
Topic archived. No new replies allowed.