WIthin c language you have can do functions as define within the header file.
For instance:
#if defined(linux) || defined(__APPLE__)
# if !defined(TRUE)
# define TRUE 1
# endif
# if !defined(FALSE)
# define FALSE 0
# endif
# if !defined(max)
# define max(a,b) (((a) > (b)) ? (a) : (b))
# endif
# if !defined(min)
# define min(a,b) (((a) < (b)) ? (a) : (b))
# endif
# if !defined(MB_OK)
# define MB_OK 0
# endif
# if !defined(Sleep)
# define Sleep(x) usleep((x) * 1000)
# endif
#endif /* linux || __APPLE__ */
Or you could do something like this which is a macro.
#define TEST_DEVICE(X) (((X).errorCode) != HD_SUCCESS)
So usually within header files we just include typedefs, defines, and functions.
IF we include functions, then in the main class we implement those functions. Think of it as a interface.
For instance:
index.h
=================================
void hdBeginFrame(int hHD);
void hdEndFrame(int hHD);
index.c
=====================
void hdBeginFrame(int hHD) {
.....
}
So instead of declaring the functions in your .c file at the beginning , you could do them within the header file.
IT acts as a interface in other languages. The reason why we have .h files is simple portability. When developers compile their code or module into dlls or so objects and they want their clients to use them, they can check the .h files to see which functions are included within that dll.
That is how we can do it. :)
2006-06-14 19:34:03
·
answer #1
·
answered by ? 6
·
0⤊
0⤋
You can write the functions in the header file if you like, be sure to include the necessary class declarations and header file declarations in the .cpp. You could also place your functions at the end of your main function in the .cpp
2006-06-15 02:30:03
·
answer #2
·
answered by nickhurry 1
·
0⤊
0⤋
just define or declare the functiom in the header file and do the rest in ur C code. But ermember to include the header file. And keep notice of < and "
2006-06-15 02:27:57
·
answer #3
·
answered by Puru 1
·
0⤊
0⤋
1)lets say u have function name myfunc() in Function.h
void MyFunc();
2)now make a Function.cpp file and write following lines in it
void MyFunc()
{
printf("hello");
}
now, make another file named Main.c , which contains ur main() method
Include function.h in ur main.c file by putting this line at the top
<#inculde function.h>
Then goes the main() function
void main()
{
//call myfunc to print on the screen
MyFunc();
}
2006-06-15 02:33:55
·
answer #4
·
answered by Shahzad Ahmed 2
·
0⤊
0⤋
Write your functions in a C file (with extension .c) and then include that file in any other C program using double quotes:
#include"file.c"
Note: Your file.c should be in same folder in which you C program which is using file.c, is kept.
2006-06-15 02:31:06
·
answer #5
·
answered by Anonymous
·
0⤊
0⤋
you can save you code in .h extention and you can include that code in any of your project.
2006-06-15 03:53:18
·
answer #6
·
answered by Anonymous
·
0⤊
0⤋