Karsten said:
I figured so... I meant that I don't know what should go into them.
If this was a joke, I apologise for my lack of insight
Er, yes, it was, but the rest of my article was intended seriously.
Just to give you a simple idea of what might go into a header, take a look
at:
http://users.powernet.co.uk/eton/c/fgetdata.h
http://users.powernet.co.uk/eton/c/fgetword.c
http://users.powernet.co.uk/eton/c/fgetline.c
(fgetword() reads an entire word of text, no matter how large, into a
buffer, resizing the buffer as necessary. fgetline() does the same for
lines.)
To use these functions, the programmer must #include "fgetdata.h" - but what
is /in/ fgetdata.h? Let's see...
Well, okay, there's a huge comment at the beginning. We'll skip over that,
and then we find this:
#ifndef FGETDATA_H_ /* See Note A */
#define FGETDATA_H_ 1 /* See Note A */
#include <stdio.h> /* See Note B */
/* Next three lines: See Note C */
#define FGDATA_BUFSIZ BUFSIZ /* adjust to taste */
#define FGDATA_WRDSIZ sizeof("floccinaucinihilipilification")
#define FGDATA_REDUCE 1
/* This space intentionally left blank -
See Note D */
int fgetline(char **line, size_t *size, size_t maxrecsize, FILE *fp,
unsigned int flags); /* See Note E */
int fgetword(char **word, size_t *size, const char *delimiters, size_t
maxrecsize, FILE *fp, unsigned int flags); /* See Note E */
#endif /* See Note A */
Note A: the header is protected by "inclusion guards". These stop the
header's main contents from being copied ad nauseam into a translation unit
if it happens to have been #included a bit too enthusiastically. Working
out how it works is diverting, and shouldn't take you more than 2 minutes.
Note B: Since the header refers to the FILE type, it's a good idea to
include the necessary header for that type. This means your calling code
doesn't have to remember to #include <stdio.h> before #including /this/
header.
Note C: Symbolic constants that you want to make available to the caller can
go here, as shown.
Note D: This module didn't need any new types. If you had any, you'd want to
define them here.
Note E: Function prototypes. These are perhaps the most easily-recognised
constituents of a header.
That's pretty much all I put in headers, really - comments, preprocessing
directives, typedefs, and function prototypes. I see no reason to clutter
them up with other stuff (on the whole). If you're heavily into global
data, though, you'll want to put your external declarations (NOT the
definitions) in a header too. (I'm /not/ heavily into global data.)