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 You may use -D to define up to 20 macros on a command line. However, you cannot redefine a macro once it has been defined. If a file uses a macro, you must place the -D option before that file's name on the command line. For example, in the command cc main.c -DNEED a dd.c the macro "NEED" is defined for add.c but not defined for main.c. The -U option undefies a macro defined by a #define in each source file. The form -D name sets name to 0. The form -U name = string redefines name as the given string. Defining Include Directories You can explicitly define directories containing "include" files by using the -1 (for "include") option. This option adds the given directory to a list of directories to be searched for include files. The directories in the list are searched whenever an include directive is encountered in the source file. The option has the form -Idirectoryname where directoryname is a valid path name to a directory containing include files. For example, the command cc -1/usr/joe/include main.c causes the compiler to search the directory /usr/joe/include for include files requested by the source file main.c. The directories are searched in the order they are listed and only until the given include file is found. The /usr/include directory is the default include directory and is automatically searched after directories given with -1. Ignoring the Default Include Directories You can prevent the C preprocessor from searching the default include directory by using the -X option. This option is generally used with the -1 option to define the location of include files that have the same names as those found in the default directories, but which contain different definitions. For example, the command cc -X -1/usr/joe/include main.c add.c causes cc to look for all include files only in the directory /usr/joe/include. 2-13

cc: C Compiler XENIX Programming Saving a Preprocessed Source File You can save a copy of the preprocessed source file by using the -P and -E options. The file is identical to the original source file except that all C preprocesor directives and macros have been expanded or replaced. The -P option copies the result to the file named fiZename.i, where filename is the same name as the source file without the ".c" extension. The -E option copies the result to the standard output and places a add.i creates a preprocessed file from the source file add.c. The output is redirected to the file add.i. Note that -P and -E suppress compilation of the source file. Thus, no object file or program is created. Error Messages The C compiler generates a broad range of error and warning messages to help you locate errors and potential problems in programs. In addition to compiler messages, the cc command also displays error messages generated by the XENIX C preprocessor and the XENIX assembler and linker programs. The following sections describe the form and meaning of the compiler error messages and warning messages you can encounter while using the cc command. C Compiler Messages The C compiler displays messages about syntactic and semantic errors in a source file, such as misplaced punctuation, illegal use of operators, and undeclared variables. It also displays warning messages about statements containing potential problems caused by data conversions or the mismatch of types. Error and warning messages have the form filename ( linenumber ) : message where filename is the na me of the source file being compiled, linenumber is the number of the line in the source file containing the error, and message is a self-explanatory description of the error or warning. If an error is severe, the compiler displays a message and terminates the compilation. Otherwise, the compiler continues looking for other errors but does not create an object file. If only warning messages are displayed, the compiler completes compilation and creates an object file. 2-14

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

You may use -D to define up to 20 macros on a command line. However, you cannot<br />

redefine a macro once it has been defined. If a file uses a macro, you must place the -D<br />

option before that file's name on the command line. For example, in the command<br />

cc main.c -DNEED a dd.c<br />

the macro "NEED" is defined for add.c but not defined for main.c.<br />

The -U option undefies a macro defined by a #define in each source file. The form -D<br />

name sets name to 0. The form -U name = string redefines name as the given string.<br />

Defining Include Directories<br />

You can explicitly define directories containing "include" files by using the -1 (for<br />

"include") option. This option adds the given directory to a list of directories to be<br />

searched for include files. The directories in the list are searched whenever an include<br />

directive is encountered in the source file. The option has the form<br />

-Idirectoryname<br />

where directoryname is a valid path name to a directory containing include files. For<br />

example, the command<br />

cc -1/usr/joe/include main.c<br />

causes the compiler to search the directory /usr/joe/include for include files requested<br />

by the source file main.c.<br />

The directories are searched in the order they are listed and only until the given include<br />

file is found. The /usr/include directory is the default include directory and is<br />

automatically searched after directories given with -1.<br />

Ignoring the Default Include Directories<br />

You can prevent the C preprocessor from searching the default include directory by<br />

using the -X option. This option is generally used with the -1 option to define the<br />

location of include files that have the same names as those found in the default<br />

directories, but which contain different definitions. For example, the command<br />

cc -X -1/usr/joe/include main.c add.c<br />

causes cc to look for all include files only in the directory /usr/joe/include.<br />

2-13

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

Saved successfully!

Ooh no, something went wrong!