C Module System C and Data Structures Baojian Hua

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

CSE 105 Structured Programming Language (C)
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
C Module System C and Data Structures Baojian Hua
CSE 303 Lecture 16 Multi-file (larger) programs
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Embedded Systems Programming Introduction to cross development techniques.
Functions C and Data Structures Baojian Hua
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
C Module System C and Data Structures Baojian Hua
C and Data Structures Baojian Hua
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
COP4020 Programming Languages
CHAPTER 1: INTORDUCTION TO C LANGUAGE
UFCFX5-15-3Mobile Device Development UFCFX Mobile Device Development An Introduction to the Module.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Programming With C.
Lecture-1 Compilation process
EG280 Computer Science for Engineers Fundamental Concepts Chapter 1.
Topic 2d High-Level languages and Systems Software
UNIT 13 Separate Compilation.
CS 213 Fall 1998 Namespaces Inline functions Preprocessing Compiling Name mangling Linking.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
CSCI 171 Presentation 8 Built-in Functions, Preprocessor Directives, and Macros.
38 4/11/98 CSE 143 Modules [Chapter 2]. 39 4/11/98 What is a Module?  Collection of related items packaged together  Examples:  Stereo System Components.
MODULAR ORGANIZATION Prepared by MMD, Edited by MSY1.
Slide Advanced Programming 2004, based on LY Stefanus's slides Native Methods.
15. WRITING LARGE PROGRAMS. Source Files A program may be divided into any number of source files. Source files have the extension.c by convention. Source.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Chapter 12: Programming in the Large By: Suraya Alias 1-1.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
ECE 103 Engineering Programming Chapter 7 Compiling C Programs Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
ITP 109 Week 2 Trina Gregory Introduction to Java.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Operating Systems A Biswas, Dept. of Information Technology.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Computer System Structures
Ashima Wadhwa Assistant Professor(giBS)
Executable program (p1)
Separate Compilation and Namespaces
Linking & Loading.
Introduction to Operating System
CS-3013 Operating Systems C-term 2008
CS1010 Programming Methodology
CS1010 Programming Methodology
مباني كامپيوتر و برنامه سازي
CMP 131 Introduction to Computer Programming
Linking & Loading CS-502 Operating Systems
C++ Compilation Model C++ is a compiled language
Program Execution in Linux
C Preprocessing File I/O
Let’s start from the beginning
Linking & Loading CS-502 Operating Systems
Compiler vs linker The compiler translates one .c file into a .o file
System Programming By Prof.Naveed Zishan.
Executable program (p1)
SPL – PS1 Introduction to C++.
Preprocessor Directives and Macros Chapter 21
Presentation transcript:

C Module System C and Data Structures Baojian Hua

Software System is Large Practical software systems tend to be large and complex: Linux kernel consists of ~1000K LOC So the general principals in designing large (even small) software systems are: dividing into manageable smaller ones separating specification (interface) from code (implementation)

Module System Different styles of module systems in languages: ML signature and structure Java interface and class C (C++) header files (.h) and C files (.c) We show, in this slide, how to manage C ’ s module system: source programs (separate) compiling, linking, loading and tools

Typical C Program Organization Program file1 function1functionm … … … filen function1functionn

General Process // Take MS cl as example, the process from source // files (.c.h) to executables (.exe): 1.c 2.c n.c 1.i 2.i n.i 1.obj 2.obj n.obj libraries a.exe preprocessingCompiling linking ………

Example // area.h #ifndef AREA_H #define AREA_H double area (int r); #endif // main.c #include “area.h” … // area.c #include “area.h” double area (int r) { double pi = 3.14; double f = pi *r *r; return f; }

Preprocessing Take source files (.c.h), generate intermediate files (.i) file inclusion Macro substitution comments removal … afterwards, no header file needed any more See demo …

Compiling Generate binary object files (.obj) object files in assembly or binary may involve several intermediate phases analysis optimizations … See demo …

Linking Object files often called relocatable they are incomplete function names, extern variables, etc. Linking the process of linking all object files together resolve reference to external entities See demo …

Linking // Object files are incomplete: // main.obj call area call printf

Linking // Resolve external references: // main.obj call area call printf // area.obj area: … // printf.obj printf: …

What are Libraries? Libraries just are pre-written pre-compiled object files Normally offered by the compiler company For user program linking purpose Header files are available Ex: stdio.h, stdlib.h, ctype.h, …, from C standard library Source code available (ex: gcc), or unavailable (ex: cl) Same linking technique, but …

How to Implement Libraries? In order to familiarize you with libraries implementation techniques and others, we next study carefully an example stdio.h Our goal is to examine the printf function: int printf (const char *format, …);

General Strategy User program call the library function printf () printf () internally makes operating system call to do the real work details vary on different OS OS calls hardware driver Offered by hardware company user program libraries: printf() OS routine hardware driver

Case Study: Linux vs Windows fwrite () user program write () int 0x80 sys_write () Kernel fwrite () user program write () NtWriteFile () int 0x2e IoWriteFile () Kernel

API & SDK Application programming interface (API) a set of routines that nicely wrap up operating system calls on which, libraries are built standard C libraries, runtime, etc. Why API? Software Development Kit (SDK) A collection of APIs header, libraries, files, and tools Varies on different Windows version

Runtime Runtime is a special set of libraries For program startup and exit get system info libraries preparation, etc. Normally NOT for called by user program Again, vary between different systems