CC - C++ compiler
DESCRIPTION
CC is the HP-UX C++ compiler.
Arguments whose names end with .C or .c are understood to be C++ source files.
usage:
CC file.cpp compiles file.c and writes executable to a.out
CC -o obj file.cpp compiles file.cpp and names executable obj
CC -c file.cpp compiles but does not link. Output to file.o
make Runs the make utility
The following makefile examples will show
(1) a basic makefile,
(2) a makefile that allows the use of the UNIX xdb debugger, and
(3) a makefile with simple macros.
The makefile syntax is:
target: dependencies
action
(The action line must begin with a TAB character)
In other words -
target: what_it_needs
Create the makefile using your favorite editor. The usual name for the file is
makefile. If you use another name, use the -f option:
e.g. make -f my makefile
The make utility uses the following logic:
if (one or more dependencies is newer than the target)
make each newer dependency file
execute action
Notes: The makefile does not have to be in the same directory
as your other files. (A path must be specified if the makefile is
in another directory). Also, a pound sign (#) is used for comments.
Lastly, to initiate the makefile at the command line type make
( If there is more than one target in the make file, type make targetname )
In the first example makefile, the following files will be used:
main.cpp, xclass.h, xclass.cpp, yclass.h, yclass.cpp
The file main.cpp uses xclass and yclass.
*****************************************************************
# A simple makefile The program's name is main
# main depends on main.o xclass.o yclass.o
# the second line is the command to link them and form the
# executable main
# Don't forget the TAB in the action lines.
main: main.o xclass.o yclass.o
CC -o main main.o xclass.o yclass.o
main.o: main.cpp xclass.h yclass.h
CC -c main.cpp
xclass.o: xclass.cpp xclass.h
CC -c xclass.cpp
yclass.o: yclass.cpp yclass.h
CC -c yclass.cpp
*****************************************************************
# Macro follows: To compile without debug option, insert the # before
# the line "CC = CC -g" and remove the # before the other line.
CC = CC -g
#CC = CC
main: main.o xclass.o yclass.o
$(CC) -o main main.o xclass.o yclass.o
main.o: main.cpp xclass.h yclass.h
$(CC) -c main.cpp
xclass.o: xclass.cpp xclass.h
$(CC) -c xclass.cpp
yclass.o: yclass.cpp yclass.h
$(CC) -c yclass.cpp
*****************************************************************
In the last example, there is an additional macro and a new target.
Note that the clean target has no dependencies, so the action line will
be executed every time "make clean" is typed.
It will remove the object files and the core dump file.
*****************************************************************
CC = CC
#CC = CC -g
OBJ = main.o xclass.o yclass.o xclass.o
main: $(OBJ)
$(CC) -o main $(OBJ)
main.o: main.cpp
$(CC) -c main.cpp
xclass.o: xclass.cpp xclass.h
*****************************************************************
CC = CC
#CC = CC -g
OBJ = main.o xclass.o yclass.o xclass.o
main: $(OBJ)
$(CC) -o main $(OBJ)
main.o: main.cpp
$(CC) -c main.cpp
xclass.o: xclass.cpp xclass.h
yclass.o: yclass.cpp yclass.h
$(CC) -c yclass.cpp
zclass.o: zclass.cpp zclass.h
$(CC) -c zclass.cpp
clean:
rm *.o core
*****************************************************************
for C/C++ control statement
SYNTAX
for ( ex1; ex2; ex3)
statement;
DESCRIPTION
The FOR loop iterates through loop statement until expression 2 is
0. If expression 2 is not zero then expression three is evaluated.
Express 1 is normally used to set the loop variables, but may be used for
other purposes if desired.
EXAMPLE
for(x=5; x!=0; x++)
cout << "Number = " << endl;
output
Number = 5
Number = 4
Number = 3
Number = 2
if -- if-then else C/C++ control statement
SYNTAX
(1) if (exp)
statement;
(2) if (exp)
statement;
else
statement;
Example
if(x==1)
cout << "1" << endl;
else
cout << "0" << endl;
otherwise the else statement will be executed.