RE: [Dev-C++] what is a resource? how do I create my own headers?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2001-01-04 15:00:51
|
Well, one can write the functions declarations in one .h file e.g. magic.h
so as the user (programmer) sees them, and the implementations in a .c (or
.cpp) file .e.g. magic.c and place an #include "magic.c" line at the end of
the header file. Or he can place the implementations too with (or without)
the functions' declarations.
So in the program he can directly use #include "magic.h" .
E.g. a function:
void tweety(void)
{
printf("\nI think thhat i see a caty\n");
}
a) In magic.h:
void tweety(void); // The user interface. The interface which another user
sees without bothering
// with implemetation details
#include magic.c
-----------------------
In magic.c:
#include <stdio.h>
void tweety(void)
{
printf("\nI think that i see a caty\n");
}
b) In magic.h:
void tweety(void); // The user interface. The interface which another user
sees without bothering
// with implemetation details
// Here the implementation begins. User interface and implementation on the
same file
#include <stdio.h>
void tweety(void)
{
printf("\nI think that i see a caty\n");
}
c) magic.h:
// implementation only. The user must scroll through implementation details
to discover the user interface.
// NOT recommended.
#include <stdio.h>
void tweety(void)
{
printf("\nI think that i see a caty\n");
}
----------------------------------------------------------------------------
-----------------------------------------------------
The main point here is that where you place an #include preprocessor
command, is the same as if you typed the contents of the file you #included
in that place. One can #include whattever file he wants, e.g. #include
"test.txt".
Most compilers have an automation feature that when you #include a header
file, it #includes the corresponding .c or .cpp file, but do not rely on
automations.
Ioannis
|