|
Example: the following C program that consists of 2 program files:
main1.c | func1.c |
---|---|
#include <stdio.h>
// Notice: no function declaration used
int main(int argc, char *argv[])
{
int a = 4, b;
b = square(a);
printf("square(%d) = %d\n", a, b);
}
|
int square( int x )
{
int r;
r = x * x;
return ( r );
}
|
Commands used to compile this C program:
gcc -c main1.c # Compile main1.c gcc -c func1.c # Compile func1.c gcc -o main1 main1.o func1.o # Link |
DEMO: demo/C/set4/main1.c + func1.c
|
Suppose we made a change in the program file main1.c:
main1.c | func1.c |
---|---|
#include <stdio.h>
int main(int argc, char *argv[])
{
int a = 4, b;
b = square(a);
printf("%d^2 = %d\n", a, b);
}
|
int square( int x )
{
int r;
r = x * x;
return ( r );
}
|
Commands used to re-compile this C program into the executable program are:
gcc -c main1.c # Re-compile main1.c
gcc -o main1 main1.o func1.o # Link
|
DEMO: demo/C/set4/main1.c + func1.c