Separate Compilation
Here is what the program we just wrote would
look like if it were all in one file. Nasty isn't it.
To make this program a little more managable it can be divided up into three
separate files:
- main
- function implementation
- header file
After you have created all the files, you compile them together by using the -c switch with cc. Here is a sample run:
[irix2]> cc -c separatecomp.c mathfunc.c
separatecomp.c:
mathfunc.c:
[irix2]> cc separatecomp.o mathfunc.o
[irix2]> a.out
This program will find the approximate square root of any positive
real number you enter. First, it finds thesquare root by
successive approximation. This approximate square root will then
be compared to the square root computed using the sqrt function
found in the math library. A comparison of these values will be
done and the difference shown in exponential notation.
Please enter a positive real number: 4.567
You entered 4.567000
The approximate square root of 4.567000 is 2.137054
The sqrt function reports it as 2.137054
The difference is 4.768372e-07
[irix2]>
Main Page
Last Modified 3 October 2000