CC Compiling 1 A Brief History of C

C/C++ Compiling 1

A Brief History of C language • In the early 1970 s, Dennis Ritchie of Bell Laboratories was engaged in a project to develop new operating system. • He realized that he needed the use of a programming language that was concise and that produced compact and speedy programs. • This need led Ritchie to develop the programming language called C. 2

A Brief History of C++ • In the early 1980's, also at Bell Laboratories, another programming language was created which was based upon the C language. • This new language was developed by Bjarne Stroustrup and was called C++. According to Stroustrup, the purpose of C++ is to make writing good programs easier and more pleasant for the individual programmer. • When he designed C++, he added OOP (Object Oriented Programming) features to C without significantly changing the C component. Thus C++ is a "relative" of C, meaning that any valid C program is also a valid C++ program. 3

Simple C program // Add two numbers and print the result #include <iostream. h> using namespace std; void main() { int first. Num, second. Num, result; cout<< “Please Enter the first Number”<<endl; cin>> first. Num; cout<< “Please Enter the second Number”<<endl; cin>> second. Num; result= first. Num + second. Num; cout<<first. Num<<“ + “<<second. Num<<“ = “<<result<<endl; } 4

C/C++ source files suffixes • . cpp, . cc, . c suffixes are used for C++ programs that are to be preprocessed, compiled and assembled • . c for C programs that are to be processed, compiled and assembled • . h or preprocessor (header) files 5

File Structure • Implementation files (. cpp, . cc, . c) – Methods are implemented • Interface files (. h) – Methods and classes are defined – Also called header files • Implementation files depend on Interface files. – Interface holds prototypes and definitions – Implementation holds actual code 6

Compilation Details Source code Assembly Machine Code object. cpp object. s object. o object. h Output main. s main. o main. cpp 7

Using GNU C Compiler • GNU C compiler is one of the compilers installed on willow server (UM research server) • GCC is the official compiler of the GNU • gcc file 1. c command is used to compile and link a C program on willow with the gcc compiler • g++ file 1. c command is used to compile and link a C++ program on willow with the gcc compiler • gcc prog. c command creates an executable file known as a. out 8
![More on gcc command gcc filename [flag] -c Compile or assemble the source files, More on gcc command gcc filename [flag] -c Compile or assemble the source files,](http://slidetodoc.com/presentation_image_h2/a67009427ccb1405b5173e9e06228dd2/image-9.jpg)
More on gcc command gcc filename [flag] -c Compile or assemble the source files, but do not link. -S Stop after the stage of compilation proper; do not assemble. -E Stop after the preprocessing stage; do not run the compiler proper. -o new. Filename Place output in file new. Filename instead of a. out 9
- Slides: 9