Sure.
When you make a function, a certain variable is usually declared for the variable that the program is passing to the function. Basically, How would the function in the include be able to read the variable passed to it by the program? Please give me code examples. Thank you.
You're overcomplicating matters; suppose I have two great functions, foo and bar:
-
int foo(double d) { /* great stuff goes on in here ... */ }
-
int bar(long l) { /* even greater stuff goes on in here */ }
-
I can build a header file foobar.h for those great functions like this:
-
#ifndef FOO_BAR
-
#define FOO_BAR
-
extern int foo(double);
-
extern int bar(long);
-
#endif
-
and all I have to do is to include that header file in other source files:
-
#include "foobar.h"
-
-
int main() {
-
int r1= foo(3.1415);
-
int r2= bar(12345678L);
-
/* other stuff here ... */
-
return 0;
-
}
-
When it comes to linking, the functions foo and bar should be available of course,
maybe in a library or as a compiled translation unit of their own. The compiler
just assumes function foo and bar exist somewhere because I declared them so
in my include file foobar.h. Note the little tag at the top of the include file that
protects the content of the file to be included more than once.
kind regards,
Jos