09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>XENIX</strong> Programming cc: C Compiler<br />

You can execute the new program by typing<br />

a.out<br />

The program waits until you enter two numbers, then prints their sum. For example, if<br />

you type "3 5" the program displays "8".<br />

Compiling Several Source Files<br />

Large source programs are often split into several files to make them easier to<br />

understand, update, and edit. You can compile such a program by giving the names of<br />

all the files belonging to the program when you invoke the cc command. The command<br />

reads and compiles each file in turn, then links all object files together, and copies the<br />

new program to the file a.out.<br />

To compile several source files, type<br />

cc filename •<br />

• •<br />

where each filename is separated from the next by at least one space. One of these<br />

files (and only one) must contain a "main" function. The others may contain functions<br />

called by this "main" function or by other functions in the program. The files must not<br />

contain calls to functions not explicitly defined by the program or by the standard C<br />

library.<br />

For example, suppose the following main program function is stored in the file main.<br />

#include <br />

extern int add();<br />

main ()<br />

{<br />

int x,y,z;<br />

}<br />

scanf ("%d %d", &x, &y);<br />

z = add (x, y);<br />

printf (" %d \n", z);<br />

Assume that the following function is stored in the file add.c.<br />

add (a, b)<br />

int a, b;<br />

{<br />

return (a + b);<br />

}<br />

You can compile these files and create an executable program by typing<br />

cc main.c add.c<br />

2-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!