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

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

09.06.2013 Views

XENIX Programming cc: C Compiler To create an assembly language listing, give the name of the desired source file. For example, the command cc -5 add.c creates an assembly language listing file named add.s and the command cc -L mult.c creates a listing file named mult.L. Note that both the -S and -L options suppress subsequent compilation of the source file; they imply the -c option. Thus, no program file is creat ed and no linking is performed. Another use of the -S option is to create an assembly language source file that may be optimized by hand and later submitted to masm for translation. Although this method can be useful, optimizing should be left to the compiler whenever possible. The -S and -L options apply to source files only; the compiler cannot create an assembly language listing file from an existing object file. Furthermore, the options in the command line must appear before the names of the files for which the assem bly listings are to be saved. Profiling a Program You can examine the flow of execution of a program by adding "profiling" code to the program with the -p option. The profiling code automatically keeps a record of the number of times program functions are called during execution of the program. This record is written to the mon.out file and can be examined with the prof command. For example, the command cc -p main.c adds profiling code to the program created from the source file main.c. The profiling code automatically calls the monitor function, which creates the mon.out file at normal termination of the program. The prof command is described in Appendix B, "Programm ing Commands." The monitor function is described in "System Functions" in the XENIX 286 C Library Guide. The -p option must be given in any command line that links object files containing profiling code. For example, if the command cc -c -p f1.c f2.c was used to create the object files fl.o and f2.o, then the command cc -p f1.o f2.o must be used to create an executable program from these files. 2-11

cc: C Compiler XENIX Programming Controlling the C Preprocessor The cc command provides a number of options to control the operation of the C preprocessor. These options can define macros, modify the new search path to include files, and suppress subsequent compilation of the preprocessed source file. Defining a Macro You can define the value or meaning of a macro used in a source file by using the -D (for "define") option. The -D option assigns a value to a macro when you invoke the compiler and is useful if you have used if, ifdef, and ifndef directives in your source files. The option has the form -Dname'[ =string ] where name is the name of the macro and string is its value or meaning. If no string is given, the macro is defined and its value is set to 1. For example, the command cc -DNEED = 2 main.c sets the macro "NEED" to the value "2". This has the same effect as having the directive #define NEED 2 in the source file. The command compiles the source file main.c, replacing every occurrence of "NEED" with "2". The -D option is especially useful with the ifdef directive. You can use the option to determine which statements in the source are to be compiled. For example, suppose a source file, main.c, contains the directive #ifdef NEED but no explicit define directive for the macro "NEED". Then all statements controlled by the ifdef directive would be compiled only if you supply an explicit definition of "NEED" by using -D. For example, the command cc -DNEED main.c is sufficient to compile all statements controlled by the ifdef directive, while the com mand cc main.c causes those statements to be ignored. 2-1 2

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

Controlling the C Preprocessor<br />

The cc command provides a number of options to control the operation of the C<br />

preprocessor. These options can define macros, modify the new search path to include<br />

files, and suppress subsequent compilation of the preprocessed source file.<br />

Defining a Macro<br />

You can define the value or meaning of a macro used in a source file by using the -D<br />

(for "define") option. The -D option assigns a value to a macro when you invoke the<br />

compiler and is useful if you have used if, ifdef, and ifndef directives in your source<br />

files.<br />

The option has the form<br />

-Dname'[ =string ]<br />

where name is the name of the macro and string is its value or meaning. If no string is<br />

given, the macro is defined and its value is set to 1. For example, the command<br />

cc -DNEED = 2 main.c<br />

sets the macro "NEED" to the value "2". This has the same effect as having the<br />

directive<br />

#define NEED 2<br />

in the source file. The command compiles the source file main.c, replacing every<br />

occurrence of "NEED" with "2".<br />

The -D option is especially useful with the ifdef directive. You can use the option to<br />

determine which statements in the source are to be compiled. For example, suppose a<br />

source file, main.c, contains the directive<br />

#ifdef NEED<br />

but no explicit define directive for the macro "NEED". Then all statements controlled<br />

by the ifdef directive would be compiled only if you supply an explicit definition of<br />

"NEED" by using -D. For example, the command<br />

cc -DNEED main.c<br />

is sufficient to compile all statements controlled by the ifdef directive, while the<br />

com mand<br />

cc main.c<br />

causes those statements to be ignored.<br />

2-1 2

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

Saved successfully!

Ooh no, something went wrong!