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 />

Creating Smaller and Faster Programs<br />

You can create smaller and faster C programs by using the optimizing options available<br />

with the cc command. These options reduce the size of a compiled program by<br />

removing unnecessary or redundant instructions or unnecessary sym bol information.<br />

Smaller programs usually run faster and save valuable space.<br />

Creati ng Opti mized Object Files<br />

You can create an optimized object file or an optimized program from a given source<br />

file by using the -0 (for "optimize") option. This option reduces the size of the object<br />

file or program by removing unnecessary instructions. For example, the command<br />

cc -0 main.c<br />

creates an optimized program from the source file main.c. The resulting object file or<br />

program is smaller (in bytes) than if the source had been compiled without the option. A<br />

smaller object file usually means faster execution.<br />

The -0 option applies to source files only; existing object files are not optimized if<br />

included with this option. The option must appear before the names of the files you<br />

wish to optimize. For example, the command<br />

cc -0 add.c main.c<br />

optimizes add.c and main.c. You have different levels of optimization available, The<br />

default is to favor code size and execution time. See the cc man page in Appendix 8<br />

for more information about levels of optimization.<br />

You can combine the -0 and -c options to compile and optimize source files without<br />

linking the resulting object files. For example, the command<br />

cc -0 -c main.c add.c<br />

creates separate optimized object files from the source files main.c and add.c.<br />

Although optimization is very useful for large programs, it takes more time than regular<br />

compilation. In general, it should be used in the last stage of program development,<br />

after the program has been debugged.<br />

Stripping the Symbol Table<br />

You can reduce the size of a program's executable file by using the -s option. This<br />

option directs cc to remove items from the sy mbol table. The symbol table contains<br />

information about code relocation and program symbols and is used by the <strong>XENIX</strong><br />

debugger adb to allow symbolic references to variables and functions when debugging.<br />

The information in this table is not required for execution and may be removed when the<br />

program has been completely debugged.<br />

2-9

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

Saved successfully!

Ooh no, something went wrong!