SlideShare una empresa de Scribd logo
1 de 26
www.mindbridgetech.com
dhanashri@mindbridgtech.com
 pushpa@mindbridgetech.com
   Compilation stages of C program
   How C program works
   Object file format
   How to run hello world program in Linux
    environment
   C created -1972 by Dennis Ritchie
   Efficient
   Portable
   Flexible
   Three things are necessary for creating
    programs
    • Text editor                      (vi editor)
    • Compiler                         (gcc)
    • Standard libraries and headers   (glibc)
   Assembly                      Machine Language
    •   MOV     R1, 0x1000   ------   10101010
    •   MOV     R2, 0x1004   ------   11001100
    •   ADD     R1, R2       ------   11100011
    •   STA     0x1008       ------   10001000


   HLL (C program)
    • C = a+b
   Each and every statement of C program need
    to convert in such a format so that processor
    can understand it.
   Ex: Processor does not understand what is
    “printf”
   A program that translate HLL language to
    machine level language is known as compiler
   The four stages for a C program to become
    an executable
    •   Pre-processing
    •   Compilation
    •   Assembly
    •   Linking
 Begins with „#‟
 Carried out prior to compilation
 Macro substitution
 Comments are removed
 Expansion of the included files
 Saved in .i file
/* hello.c */
#include<stdio.h> /*Preprocessor directives*/
int main()
{
      printf(“Hello Worldn”);
      return 0;
}
 “hello.i” is the input to Compiler
 Compiled into intermediate stage (assembly)
  i.e. „hello.s”
/* hello.c */
#include<stdio.h> /*Preprocessor directives*/
int main()
{
      printf(“Hello Worldn”);
      return 0;
}
 “hello.s” is the input to Assembler
 Compiled into object file “hello.o”

/* hello.c */
#include<stdio.h> /*Preprocessor directives*/
int main()
{
     printf(“Hello Worldn”);
     return 0;
}
 Final stage
 “hello.o” is the input to linker
 Form executable a.out
/* hello.c */
#include<stdio.h> /*Preprocessor directives*/
int main()
{
     printf(“Hello Worldn”);
     return 0;
}
   Input             Program         Output

   src code          >Preprocessor   >expanded src code

   expanded src code >Compiler       >assembly src code

   assembly code     >Assembler      >object code

   object code       >Linker         >executable code

   executable code   >Loader         >execution
   Part of Operating system responsible for
    loading the program
   Allocates program address space
   Copies a program into main memory
   Stands for Executable and Linkable Format
   Object file
   Executables
   Shared libraries
   Each object file contains
    •   code section
    •   data section
    •   BSS (Block started by Symbol) section
    •   symbol table
   Symbol table contains information of
    • global variable,
    • external functions like printf, scanf
    • Functions defined in other object file
   not specific to particular processor or
    architecture
   adopted to many operating systems on many
    different platforms
   Combines code and data sections
   Resolves symbols for global variable
   Resolves symbols for external function and
    library function such as printf, scanf
 What is Library?
It is a collection of pre-compiled functions and
reusable code.



   In Linux, it is called glibc (GNU C library)
Library



Static Library             Shared Library




             Dynamic                Dynamic Loading
             Linking
   Link at the compilation stage into the final
    executable
   Size of the executable becomes large
    compared to shared library
   Need more RAM
   Fast
   Suitable for small program
   It just verifies the link
   Actual symbol is added at the time of running
   Size of executable become less as compared
    to Static
   Becomes slower than static library
   Used for bigger application
   C language is
    • Efficient
    • Powerful
    • Flexible
   Its being 40 years it is used extensively and
    will be used for many more years to come.
   Encourage yourself to be a good programmer
    to sustain in software industry
Understanding how C program works

Más contenido relacionado

La actualidad más candente

Source-to-Source Compiler
Source-to-Source CompilerSource-to-Source Compiler
Source-to-Source CompilerMintoo Jakhmola
 
Emscripten - compile your C/C++ to JavaScript
Emscripten - compile your C/C++ to JavaScriptEmscripten - compile your C/C++ to JavaScript
Emscripten - compile your C/C++ to JavaScript穎睿 梁
 
Compiler.design.in.c.docs
Compiler.design.in.c.docsCompiler.design.in.c.docs
Compiler.design.in.c.docsAbid Syed
 
Linker and loader upload
Linker and loader   uploadLinker and loader   upload
Linker and loader uploadBin Yang
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation processRahul Jamwal
 
An Application Using Writer as a GUI for Creating and Maintaining [e]BNFs
An Application Using Writer as a GUI for Creating and Maintaining [e]BNFsAn Application Using Writer as a GUI for Creating and Maintaining [e]BNFs
An Application Using Writer as a GUI for Creating and Maintaining [e]BNFsAlexandro Colorado
 
C Programming[Sample]
C Programming[Sample]C Programming[Sample]
C Programming[Sample]Mostafa Ali
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
QBASIC
QBASICQBASIC
QBASICnivi88
 
Compiler interpreter and_bootstrapping
Compiler interpreter and_bootstrappingCompiler interpreter and_bootstrapping
Compiler interpreter and_bootstrappingsandeep manzhi
 
Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ Safen D Taha
 
Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C LanguageSyedShujaatAbbas
 

La actualidad más candente (20)

Source-to-Source Compiler
Source-to-Source CompilerSource-to-Source Compiler
Source-to-Source Compiler
 
Emscripten - compile your C/C++ to JavaScript
Emscripten - compile your C/C++ to JavaScriptEmscripten - compile your C/C++ to JavaScript
Emscripten - compile your C/C++ to JavaScript
 
Compiler.design.in.c.docs
Compiler.design.in.c.docsCompiler.design.in.c.docs
Compiler.design.in.c.docs
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
Linker and loader upload
Linker and loader   uploadLinker and loader   upload
Linker and loader upload
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation process
 
Compiler Design Quiz
Compiler Design QuizCompiler Design Quiz
Compiler Design Quiz
 
An Application Using Writer as a GUI for Creating and Maintaining [e]BNFs
An Application Using Writer as a GUI for Creating and Maintaining [e]BNFsAn Application Using Writer as a GUI for Creating and Maintaining [e]BNFs
An Application Using Writer as a GUI for Creating and Maintaining [e]BNFs
 
C Programming[Sample]
C Programming[Sample]C Programming[Sample]
C Programming[Sample]
 
Dynamic Linker
Dynamic LinkerDynamic Linker
Dynamic Linker
 
Compiler type
Compiler typeCompiler type
Compiler type
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Dot net
Dot netDot net
Dot net
 
QBASIC
QBASICQBASIC
QBASIC
 
Compilers
CompilersCompilers
Compilers
 
Compiler interpreter and_bootstrapping
Compiler interpreter and_bootstrappingCompiler interpreter and_bootstrapping
Compiler interpreter and_bootstrapping
 
Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ
 
Compilers
CompilersCompilers
Compilers
 
Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C Language
 
01 c
01 c01 c
01 c
 

Similar a Understanding how C program works

C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Input and output in c
Input and output in cInput and output in c
Input and output in cRachana Joshi
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
Computer and multimedia Week 1 Windows Architecture.pptx
Computer and multimedia Week 1 Windows Architecture.pptxComputer and multimedia Week 1 Windows Architecture.pptx
Computer and multimedia Week 1 Windows Architecture.pptxfatahozil
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008guestd9065
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingRokonuzzaman Rony
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...bhargavi804095
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3aminmesbahi
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Shipra Swati
 

Similar a Understanding how C program works (20)

C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Input and output in c
Input and output in cInput and output in c
Input and output in c
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Computer and multimedia Week 1 Windows Architecture.pptx
Computer and multimedia Week 1 Windows Architecture.pptxComputer and multimedia Week 1 Windows Architecture.pptx
Computer and multimedia Week 1 Windows Architecture.pptx
 
C programming part1
C programming part1C programming part1
C programming part1
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
C_Intro.ppt
C_Intro.pptC_Intro.ppt
C_Intro.ppt
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
 
INTRODUCTION TO C LANGUAGE.pptx
INTRODUCTION TO C LANGUAGE.pptxINTRODUCTION TO C LANGUAGE.pptx
INTRODUCTION TO C LANGUAGE.pptx
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Unit 2 l1
Unit 2 l1Unit 2 l1
Unit 2 l1
 
First session quiz
First session quizFirst session quiz
First session quiz
 
First session quiz
First session quizFirst session quiz
First session quiz
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 

Understanding how C program works

  • 2. Compilation stages of C program  How C program works  Object file format  How to run hello world program in Linux environment
  • 3. C created -1972 by Dennis Ritchie  Efficient  Portable  Flexible
  • 4. Three things are necessary for creating programs • Text editor (vi editor) • Compiler (gcc) • Standard libraries and headers (glibc)
  • 5. Assembly Machine Language • MOV R1, 0x1000 ------ 10101010 • MOV R2, 0x1004 ------ 11001100 • ADD R1, R2 ------ 11100011 • STA 0x1008 ------ 10001000  HLL (C program) • C = a+b
  • 6. Each and every statement of C program need to convert in such a format so that processor can understand it.  Ex: Processor does not understand what is “printf”  A program that translate HLL language to machine level language is known as compiler
  • 7. The four stages for a C program to become an executable • Pre-processing • Compilation • Assembly • Linking
  • 8.  Begins with „#‟  Carried out prior to compilation  Macro substitution  Comments are removed  Expansion of the included files  Saved in .i file /* hello.c */ #include<stdio.h> /*Preprocessor directives*/ int main() { printf(“Hello Worldn”); return 0; }
  • 9.  “hello.i” is the input to Compiler  Compiled into intermediate stage (assembly) i.e. „hello.s” /* hello.c */ #include<stdio.h> /*Preprocessor directives*/ int main() { printf(“Hello Worldn”); return 0; }
  • 10.  “hello.s” is the input to Assembler  Compiled into object file “hello.o” /* hello.c */ #include<stdio.h> /*Preprocessor directives*/ int main() { printf(“Hello Worldn”); return 0; }
  • 11.  Final stage  “hello.o” is the input to linker  Form executable a.out /* hello.c */ #include<stdio.h> /*Preprocessor directives*/ int main() { printf(“Hello Worldn”); return 0; }
  • 12.
  • 13. Input Program Output  src code >Preprocessor >expanded src code  expanded src code >Compiler >assembly src code  assembly code >Assembler >object code  object code >Linker >executable code  executable code >Loader >execution
  • 14. Part of Operating system responsible for loading the program  Allocates program address space  Copies a program into main memory
  • 15. Stands for Executable and Linkable Format  Object file  Executables  Shared libraries
  • 16. Each object file contains • code section • data section • BSS (Block started by Symbol) section • symbol table  Symbol table contains information of • global variable, • external functions like printf, scanf • Functions defined in other object file
  • 17. not specific to particular processor or architecture  adopted to many operating systems on many different platforms
  • 18.
  • 19. Combines code and data sections  Resolves symbols for global variable  Resolves symbols for external function and library function such as printf, scanf
  • 20.  What is Library? It is a collection of pre-compiled functions and reusable code.  In Linux, it is called glibc (GNU C library)
  • 21. Library Static Library Shared Library Dynamic Dynamic Loading Linking
  • 22.
  • 23. Link at the compilation stage into the final executable  Size of the executable becomes large compared to shared library  Need more RAM  Fast  Suitable for small program
  • 24. It just verifies the link  Actual symbol is added at the time of running  Size of executable become less as compared to Static  Becomes slower than static library  Used for bigger application
  • 25. C language is • Efficient • Powerful • Flexible  Its being 40 years it is used extensively and will be used for many more years to come.  Encourage yourself to be a good programmer to sustain in software industry