UB Information Technology

Documentation

CC

Documentation print footer; appears at "bottom" of first page.

Adobe Reader 7 for Windows

Platform: Windows

CC

Platform: UNIX

Introduction

CC is a C++ translator. It translates C++ programs into C source code and then compiles it with the C compiler. CC is available on UBUnix.

Setup

Make sure your search path includes the default system path, and your MANPATH variable includes the default path.

CC Conventions

The filename of a C++ program must have the extension of .c, .C, .cc, .cxx, or .i. A comment in C++ begins with // and continues through the end of the line. Comments can also be placed between /* and */.

File Organization

Programs can be stored in multiple files by grouping sets of related functions into a file. Dividing the program into several logical parts can simplify the task of programming. Each file may be compiled separately and linked together to create one executable file.

CC Compilation

To compile a program, use the following command:
CC files -o exec

files is a list of all program filenames separated by spaces. exec is the name of the file that contains the executable file. Type the name of the executable file to run your program. Output is sent to your terminal (standard output) unless your program explicitly opens and writes to a file.

CC Compilation Example

Use an editor such as Emacs or vi to type in the following file named hello.C:
// This is a comment line
// Includes the stream library
#include <stream.h>

main()
{
char name[20]; // declare string

cout << "Please type in your name: ";
cin >> name; // input string

cout << "Hello " << name << "\n";
}

To compile the program and generate an executable file named hello, type:
CC hello.C -o hello

This compiles hello.C and puts the executable in a file named hello. Execute the program by typing:
hello

The following is displayed:
Please type in your name:

Now type:
John

The following is displayed:
Hello John

Redirecting Output and Input

To redirect the output of a program to a file, use > after the executable file followed by the output filename. If hello is an executable and outputfile is the output filename, use:
hello > outputfile

To redirect both errors and output, replace > with >&. In a similar way, redirecting a file to the standard input of a program can be done by placing < after the executable followed by the input filename:
hello < inputfile

Input and output redirection may be used together. For example, to use redirection on the above sample program, put the following in a file named inputfile:
John

Now on the command line, type:
hello < inputfile > outputfile

The input to the hello program comes from inputfile. The file named outputfile then contains:
Hello John

Command Line Options

Option Description
-g Retains debugging information for use with debuggers such as dbx.
-Ipath Adds path to the list of directories in which to search for library header files.
-o filename Specifies the executable filename. If the -o option is not used, the executable is named a.out.
-Ldir Puts dir in the beginning of the library search path for compiler and loader.
-lname Links library name into program.
-O Optimizes object code.

Command line options that are not used by CC are passed to cc.

Using Libraries

The following are C++ libraries:

Library Description
common Common functions (compare, read, and write).
complex Mathematical functions.
generic Macros for generating generic declarations.
stream Stream input and output functions.
task Subtask system functions.
vector Vector and stack functions.

The following are ANSI C libraries:

Library Description
math Mathematical functions.
stdio Standard I/O functions.
string String manipulation functions.
time Functions dealing with time.

You may use C++ and ANSI C libraries. To use functions in a library, include the library header file at the top of the C++ program:
#include <lib.h>

lib is the library name. For example, to use functions in the stream library, place the following at the top of the C++ program:
#include <stream.h>

When using some libraries, it is necessary to explicitly link the library to your program by using the -l command line option:
CC program.c -llib

lib is the object library name. For example, to use the functions in the mathematical library such as sin(), include the library header file at the top of the C++ program:
#include <math.h>

Then compile using the link option to include the math library:
CC program.c -lm

An executable named a.out is generated.

Runtime Errors

A runtime error is an error reported during program execution. A segmentation fault is a runtime error which occurs when an invalid memory address (such as Null) is referenced. Typically, these problems occur when using pointers or accessing data outside defined array bounds.

Additional Information

Command Description
dbx A source level C debugger.
make Maintains, updates, and regenerates related programs and files.
rcs Revision control system; stores old versions of programs.
ld Link editor; links object files.

A useful book on the C++ programming language is Programming in C++, by Dewhurst and Start, published by Prentice Hall. To read the online manual page, at the UNIX prompt, type:
man CC

 

Related Documents

Document Information

Title: CC
Document Category: UNIX
Document Number: UNX-003