-
External functions
I'm having trouble understanding how to use external functions. Does an external function have to be prototyped in a header file or can it just be prototyped in a C source file and defined in another C source file? Can you provide an example of using an external function involving 2 or more files.
-
file1:
void myfunction( void ) {...do stuff...}
file2:
void myfunction( void ); //prototype it before you use it
...stuff goes here...
...now call the function...
myfunction( );
Additionally, you could do:
file1.h
void myfunction( void );
file2:
#include "file1.h"
...now call the function...
myfunction( );
Quzah.
-
file1.c
int function (void)
{
return 1;
}
file2.c
extern int function (void);
int other_function (void)
{
int retval;
retval = function (void);
return retval;
}