Previous Next Contents Index Doc Set Home


Preface


This manual, the C User's Guide describes the C 4.2 compiler. The standard language is referred to as ANSI C. The notation K&R C refers to Kernighan and Ritchie C, which is non-ANSI (or pre-ANSI) C.


Audience

This document is intended to assist software developers write programs in the C language. This book does not discuss basic concepts of C programming.


Document Organization

This book contains the following chapters:

Chapter 1, "Introduction to the C Compiler," provides an overview to C.

Chapter 2, "cc Compiler Options," describes the compiler optionsfor the SolarisTM operating system.

Chapter 3, "Sun ANSI C Compiler-Specific Information," describes areas specific to the Sun ANSI C compiler.

Chapter 4, "Cscope: Interactively Examine a C Program," describes cscope, a C programming tool.

Chapter 5, Lint Source Code Checker," describes how to use lint, another C programming tool.

This book also includes these appendices:

This book concludes with an index.


C Compiler Documentation

Table P-1 summarizes the C compiler documentation provided with this release, and identifies where that documentation is located.

Table  P-1 Summary of C Compiler Documentation and Its Location  
Document
Online Books
Online ASCII
Online PostScript
Hard Copy

C 4.2 README File

--

/opt/SUNWspro
/READMEs/c

--

--

C 4.2 Quick Reference

--

--

--

X

C User's Guide

X

--

--

X

Error and Warning Messages file

--

/opt/SUNWspro
/READMEs
/c_lint_errors

--

--

Incremental Link Editor (ild)

X

--

--

X

Installation and Licensing Guide

X

--

--

X

Making the Transition to ANSI C

X

--

--

--

Man pages

--

/opt/SUNWspro
/man

--

--

"MP C" white paper

--

--

/opt/SUNWspro
/READMEs
/mpc.ps

--

Numerical Computation Guide

X

--

--

X

Performance Profiling Tools

X

--

--

X

Quick Install for Solaris

--

--

--

X

Online Documentation

On-line documents are in the following formats:

Online Books

Some of the C compiler documents are provided in online documentation viewing tools. These online documents provide the following benefits:

See your platform-specific installation guide and README file for more information on these tools.

The following C compiler documentation is provided in online books:

Manual Pages

Each manual page (man page), discusses one subject, such as a user command or library function. The C man pages are in /opt/SUNWspro/man.

To view a man page using the man command:

1. Insert the name of the directory in which you installed the C compiler at the beginning of your search path.

2. Add a line to the .cshrc file with setenv MANPATH= at the start or, to the .profile file with export MANPATH= at the start.

3. Now, view a man page by executing this command:

% man command_name
where command_name is cc, for example.

Table P-2 describes the C man pages, and identifies the best uses for each man page.

Table  P-2 C Man Pages and their Usage
Title
Description
Usage
cb

Formats your source code.

Makes the program more readable.

cc

Describes the C compilation system.

Provides C system information.

cflow

Produces a flow graph of the external references in C, lex, yacc, and assembly-language files.

Checks program dependencies.

cscope

Interactively examines a C program.

Searches and edits source files.

ctrace

Traces C program execution, statement by statement.

Checks program execution statements.

cxref

Generates a C program cross-reference table.

Checks program dependencies and structure.

c89

Enables compliance with XPG4.

Verifies XPG4 comopliance.

indent

Indents and formats a C program source file.

Indents and formats source file.

lint

The C program checker.

Checks for code constructs that may cause the program to not compile or execute with unexpected results. Also checks program portability and cross-file consistency.

Table P-3 Identifies the man pages containing C compiler related information.

Table  P-3 C-Related Man Pages 
Title
Description
gprof

Includes the prof functionality, and produces a callgraph profile displaying a list of modules that call, or are called by, other modules.

ild

Contains information on the incremental ild linker.

inline

Contains information on inlining code.

m4

Preprocesses C and assembly language programs.

make

Maintains, updates, and regenerates related programs and files.

ld

Contains information on the ld linker.

lex

Describes the lexical analysis program generator.

prof

Reports time, percentage of time spent executing a program and number of calls to functions.

sccs

Provides a front end for the source code control system.

tcov

Provides a line-by-line frequency profiler that produces a copy of the source file, annotated to show which lines are used, and how often.

yacc

Parses tokens passed by a lexical analyzer.

The man man page describes the options available with the man command to browse man pages. Other tools, such as tkman, provide search features and hypertext links to the man pages listed in the "SEE ALSO" section of a man page.

To print man pages with the lp command, type:

% man command_name | lp
where command_name is cc, for example.

Error and Warning Messages File

The Error and Warning Messages file, located in /opt/SUNWspro/READMEs/c_lint_errors, contains C compiler error and warning messages, and the lint program messages. Many of the messages are self-explanatory. To obtain a description of these messages and code examples, search the text file for a string from the generated message, or obtain its unique tag and search on that (cc -errtags=yes).

There are several methods to locate an error message and its description in the file:

For example, if this message is received during a compilation:

file: filename line: n  empty constant expression after macro expansion
Obtain further explanation of this message by:

1. Loading the /opt/SUNWspro/READMEs/c_lint_errors file into an editor.

2. Searching for a string from the message, for example, "empty constant."

A more detailed description is displayed with the sample code generating the error message, and the message ID, or tag:

empty constant expression after macro expansion
A #if or #elif directive contains an expression that, after macro expansion, consists of no tokens.
#define EMPTY
#if EMPTY

char *mesg = "EMPTY is non-empty";
#end if
MESSAGE ID: E_EMPTY_CONST_EXP_AFTER_EXPAND
-----------------------------------------

To print the Error and Warning Messages file, type:

% lp /opt/SUNWspro/READMEs/c_lint_errors
When an error occurs, the error message is preceded by a file name and line number. The line number is the line where a problem is diagnosed. Occasionally, the compiler must read the next token before it can diagnose a problem, in which case the line number in the message may be a higher line number than that of the offending line.


Note - The compiler displays many of the messages contained in this file only when used with the cc -v option. With this option, the compiler performs stricter semantics checking and, therefore, displays more diagnostic messages.

C 4.2 README file

The C 4.2 README file, located in /opt/SUNWspro/READMEs/c, contains important information about the compiler, such as:

You can display this file online in your editor, print it using the lp command, or view it using the command cc -xhelp=readme.

PostScript Files

The PostScript files include "white papers" such as "MP C" white paper, MPC.ps. These files are located in /opt/SUNWspro/READMEs.

To view a PostScript file online, type:

% imagetool filename &
To print a PostScript file, type:

% lp filename

Hard-Copy Documentation

The following C documents are available in hard copy:

Related Documentation

The following documents contain useful information on programming and compiling.

The following books are useful for information on the C language:

For implementation-specific details not covered in this book, refer to the Application Binary Interface for your machine.

Typographic Conventions

Table P-4 describes the typographic conventions used in this book.

Table  P-4 Typographic Conventions in This Manual
Typeface or Symbol
Meaning
Example

AaBbCc123

The names of commands, files, and directories; onscreen computer output

Edit your .login file.

Use ls -a to list all files.

machine_name% You have mail.

AaBbCc123

What you type, contrasted with onscreen computer output

machine_name% su

Password:

AaBbCc123

Command-line placeholder:

replace with a real name or value

To delete a file, type rm filename.

AaBbCc123

Book titles, new words or terms, or words to be emphasized

Read Chapter 6 in User's Guide. These are called class options.

You must be root to do this.

Table P-5 describes the typographic notations used for arguments to the compiler and lint tool options.

Table  P-5 Typographic Notations for Arguments  
Notation
Meaning
Example

[ ]

Square brackets contain arguments that can be optional or required.

-d[y|n]

|

The "pipe" or "bar" symbol separates arguments, only one of which may be used at one time.

-d[y|n]

,

The comma separates arguments, one or more of which may be used at one time.

-xinline=[f1,...fn]

:

The colon, like the comma, is sometimes used to separate arguments.

-Rdir[:dir]

...

The ellipsis indicates omission in a series.

-xinline=[f1,...fn]

%

The percent sign indicates the word following it has a special meaning.

-ftrap=%all

`

The back quote indicates a command that is being executed.

`uname -s`

Other Documentation Conventions

Operating Environments and Platform-Specific References
The C 4.2 documentation supports the following operating environments:

The C 4.2 compiler documentation supports all the above operating systems and platforms, unless otherwise specified. Anything unique to one or more platforms is identified as "(SPARC)," "(Intel)," and/or "(PowerPC)."

Path Names
In the C compiler documentation, the pathname to many file locations is given as /opt/SUNWspro. This is the default installation location. If you installed the compiler in a different directory, substitute that directory name instead.

Shell Prompts in Command Examples
Table P-6 shows the system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell, used in the command examples.

Table  P-6 Shell Prompts
Shell
Prompt

C shell prompt

machine_name%

C shell superuser prompt

machine_name#

Bourne shell and Korn shell prompt

$

Bourne shell and Korn shell superuser prompt

#


Previous Next Contents Index Doc Set Home