Header Files
Posted: Wed Feb 01, 2006 12:33 pm
Hi. I need documents for creating C header file. Can somebody help me?
Code: Select all
const int ONE_THING = 0;
const int ANOTHER_THING = 1;
typedef struct SomeInfo {
int type;
char *name;
} SomeInfo;
SomeInfo CreateStruct(int type, char *name)
{
SomeInfo newStruct;
newStruct.type = type;
newStruct.name = name;
return newStruct;
}
Code: Select all
const int ONE_THING = 0;
const int ANOTHER_THING = 1;
typedef struct SomeInfo {
int type;
char *name;
} SomeInfo;
SomeInfo CreateStruct(int type, char *name);
Code: Select all
#include "MyCode.h"
SomeInfo CreateStruct(int type, char *name)
{
SomeInfo newStruct;
newStruct.type = type;
newStruct.name = name;
return newStruct;
}
Code: Select all
int main()
{
puts( "Hello world!" );
return 0;
}
Code: Select all
int puts( const char * );
int main()
{
puts( "Hello world!" );
return 0;
}
Code: Select all
#include <stdio.h>
int main()
{
puts( "Hello world!" );
return 0;
}
Code: Select all
int puts( const char * );
Code: Select all
void foo();
Code: Select all
#include <stdio.h>
#include "foo.h"
void foo()
{
puts( "Hello world!" );
}
Code: Select all
#include "foo.h"
int main()
{
foo();
return 0;
}
And yes, I know I never fixed a lot of the errors in that tutorial; I need to go back through it again but I never seem to find the time. Any help in spotting mistakes would be appreciated.The directive
[tt]#include "path/filename"[/tt]
or
[tt]#include <path/filename>[/tt]
...will cause the text of [tt]filename[/tt] to be inserted into the source stream at the point where the directive occurs. For example, given the file foo.h,which is then used in file foo.cCode: Select all
/* foo.h */ extern int bar; float foo();
Code: Select all
/* foo.c */ float baz = 3; #include "foo.h" int bar = 10; float foo() { return bar * baz; /* multiply the current values of bar and baz */ }
the preprocessor would produce:Code: Select all
float baz = 3; extern int bar; float foo(); int bar = 10; float foo() { return bar * baz; }
By long-standing convention, this is used almost exclusively to include header files, which are source files containing only constant definitions, type and class definitions,external variable references, and function prototypes which are to be shared between two or more source files. Generally speaking, actual variable declarations and function definitions are not put into header files, as this can lead to redeclaration errors when linking the resulting object files.