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.

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

Creating Progra ms from C Source Files<br />

The cc command is normally used to create executable programs from C language<br />

source files. A file's contents are identified by the file name extension. C source files<br />

must have the extension ".c".<br />

The cc command can create executable programs only from source files that make up a<br />

complete C program. In <strong>XENIX</strong>, a complete program must have one (and only one)<br />

function named "main". This function becomes the entry point for program execution.<br />

The "main" function may call other functions as long as they are defined within the<br />

program or are part of the C standard library. The standard C library is described in the<br />

<strong>XENIX</strong> <strong>2<strong>86</strong></strong> C Library <strong>Guide</strong>.<br />

Compiling a C Source File<br />

You can compile a C source file by giving the name of the file when you invoke the cc<br />

command. The command compiles the statements in the file, then copies the<br />

executable program to the default output file a.out.<br />

To compile a source program, type<br />

cc filename<br />

where filename is the name of the file containing the program. The program must be<br />

complete, that is, it must contain a "main" program function. It may also contain calls<br />

to functions explicitly defined by the program or by the standard C library.<br />

For example, assume that the following program is stored in the file named main.c.<br />

#include <br />

main ()<br />

{<br />

intx,y;<br />

}<br />

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

pri ntf(" %d\n", x + y);<br />

To compile this program, type<br />

cc main.c<br />

The command first invokes the C preprocessor, which adds the statements in the file<br />

/usr/include/stdio.h to the beginning of the program. It then compiles these statements<br />

and the rest of the program statements. Next, the com mand links the program with the<br />

standard C library, which contains the object files for the scanf and printf functions.<br />

Finally, it copies the program to the file a.out.<br />

2-2

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

Saved successfully!

Ooh no, something went wrong!