Presentation is loading. Please wait.

Presentation is loading. Please wait.

C/C++ Compiling.

Similar presentations


Presentation on theme: "C/C++ Compiling."— Presentation transcript:

1 C/C++ Compiling

2 A Brief History of C language
In the early 1970s, 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.

3 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.

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

5 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

6 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

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

8 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 file1.c command is used to compile and link a C program on willow with the gcc compiler g++ file1.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

9 More on gcc command gcc filename [flag] -c -S -E -o newFilename
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 newFilename Place output in file newFilename instead of a.out


Download ppt "C/C++ Compiling."

Similar presentations


Ads by Google