|
What I have shown you is what I normally used.
Here is the official syntax....
extern returnType functionName ( param1type, param2type, .... ) |
Meaning:
|
Example:
| File func3a.c containing the main function | File func3b.c containing the other functions |
|---|---|
extern double square ( double ); int main( int argc, char *argv[] ) { double a, b; a = 4.0; b = square( a ); // Call square printf("Square of %d = %d\n", a, b); } |
double square ( double x )
{
double r; // Local variable
r = x * x; // Statement
return ( r ); // Return
}
|
How to run the program:
|
Result:
Number = 4.000000 Number = 16.000000 (correct !) |
|
|
Example:
| File func4a.c containing the main function | File func4b.c containing the other functions |
|---|---|
extern double square ( double x ); int main( int argc, char *argv[] ) { double a, b; a = 4.0; b = square( a ); // Call square } |
double square ( double x )
{
double r; // Local variable
r = x * x; // Statement
return ( r ); // Return
}
|
How to run the program:
|
Result:
Number = 4.000000 Number = 16.000000 (correct !) |
|
|
|
Example:
int f( ... )
{
extern double square( double x); // declare square() function
...
}
int g( ... )
{
square() is not declared here !!!
}
|
|
C program file:
void func1( ... )
{
...
}
extern square( double x );
void func2( ... )
{
...
}
void func3( ... )
{
...
}
|
Then:
|
|
| File(s) containing the function definitions | Header file containing function declarations |
|---|---|
void print ( double x )
{
printf("Number = %lf\n", x );
}
double square ( double x )
{
double r; // Local variable
r = x * x; // Statement
return ( r ); // Return
}
|
extern void print( double x ); extern double square ( double x ); |
#include "header.h" // Include the function declarations int main( int argc, char *argv[] ) { double a, b; a = 4.0; b = square( a ); // Call square print( a ); // Call print print( b ); // Call print } |
This will provide all function declarations to the program !!!
How to run the program:
|
Result:
Number = 4.000000 Number = 16.000000 (correct !) |