The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsI've been searching for info on this practically forever.
One of the half-way decent resources I had shut off, so that's no help.
And Google is slutty.
If somebody would be so kind, as to give me a link to a tutorial where I could learn to code C header files, it would be appreceated.
PS: If you even mention the word "Google" in your post, I will give you The Shocker, and give it to you using your own hand...
Just a warning.
omg.
Playstation Network tag: muffin-noodle
the empty set
What C compiler are you using?
I don't think I can be to much help in any other compilers than MS VC++ since that's the compiler I use.
"no sound in ass"
Header files are easy. I'm not saying this to make you feel bad for asking; on the contrary, I think you'll be surprised they aren't more complicated.
There is nothing special you have to do to make a header file. As far as C/C++ is concerned, all code is text. You could write C/C++ in Windows Notepad if you were so inclined, and it would make no difference to your compiler and linker.
Basically, the point in making a header file is to seperate the declaration of your functions/classes seperate from the implimentation. Header files can also be used for putting configuration you want to use throughout your program (ex. declaring global constants).
There is one thing you should always do in header files, though. You should always make it so a header file is only compiled once. There are a couple reasons for this, but as a matter of practice you should always do it even if those reasons don't apply. Here is how:
example.h
-------------------------------------------------------------
#ifndef _EXAMPLE_H_
#define _EXAMPLE_H_
declarations
#endif
Empty line, just to avoid getting warnings from some compilers
-------------------------------------------------------------
#ifndef is an if statement posed to the compiler. It says, "If _EXAMPLE_H_ is not defined (in your variable table), do everything after this until you hit an #else or an #endif." #define _EXAMPLE_H_ tells the compiler to add _EXAMPLE_H_ to its variable table. As a result, the previous if-not-defined statment will never be true again. Then the compiler goes through all of your code. The extra empty line before the end of file is just there to avoid compiler warnings; of course, it takes one keystroke to add and won't alter the final size of a compiled program, so why leave it out?
So, why is it important to put in this compiler if statment? This does two important things. First, it prevents recompiling the same code. This does not cause problems if you have more than one file including "example.h". Instead of compiling the header again, all new files including it are connected to the previously compiled code instead of having their own copy. Second, it prevents some of very aggrivating errors about redefinition. I can't think of great examples of why this would happen, but a common one would be if you declared constants in a header file.
Lastly, you should base the declaration on the file name. I checked for a declaration of _EXAMPLE_H_ in a file named "example.h". This is just an easy way to prevent human error. All of your files should have unique names, so using that in your declaration will prevent duplicating them. However, you could use anything after #ifndef and #define. The only important thing is that they have the identical entry for the file they're in.
Hmm I like shockers....
So why don't you google search it?
At 2/15/05 12:06 AM, JesusCyborg wrote: stuff
God, they just let anybody post here nowadays...
Like they said, its really easy stuff. Basically its just a list of all the fuctions/variables in your class. You know a stack right? Well this is what a stack header file would look like:
#ifndef STACK_CLASS_H
#define STACK_CLASS_H
class STACK
{
public: // these functions are open to any program
// The constructors
STACK();
STACK(int size);
void Push(int element);
void Pop();
int Top();
bool Error();
~STACK(); // The Deconstructor
private:
//these variables can't be accessed by other programs
int *array;
int max_size;
int index;
bool error_flag;
}; //don't forget the ; at the end of the class
#endif
Thats the stack.h file. Now you would need a stack.cpp file that has the code for pop, push, top, and all the other functions. Throw both files into a project, and then you would be able to use a stack anywhere you want. Hope this helps.
I think he's talking about how to MAKE header files, with the library file 'n shit.
"no sound in ass"
At 2/16/05 04:47 AM, CronoMan wrote: I think he's talking about how to MAKE header files, with the library file 'n shit.
What, as in precompiled header files?
At 2/16/05 03:24 PM, irritus wrote:At 2/16/05 04:47 AM, CronoMan wrote: I think he's talking about how to MAKE header files, with the library file 'n shit.What, as in precompiled header files?
Well, even if he's not, I would be interested in learning to make libraries.