SlideShare a Scribd company logo
Modulization
Developing a Large Program
 Developing a large Program
– We can split source codes into several ~. h and ~.c files
– There are many merits of several small files instead of one big file
• Easy to maintain source codes
• Easy to co-work with other programmers
• Save time when compiling: You can just compile ~.c files which are
modified not all of source codes.
2
3
Modulization
 Split source code into separate files
#define TWO 2
typedef void VOID ;
int g;
VOID func1(VOID) ;
VOID func2(VOID ) ;
VOID main(VOID )
{
func1() ;
func2() ;
g *= TWO ;
}
file.c
VOID func1(VOID )
{
func2() ;
g += TWO ;
}
VOID func2(VOID )
{
func1() ;
g -= TWO ;
}
To be written
by friend 1
To be written
by friend 2
To be written
by me
4
Modulization
 Split source code into separate files
– Make ~.c files for each function
– Add #define, declaration, function prototypes, extern objects
Prototype of Functions
#define TWO 2
typedef void VOID ;
int g;
VOID func1(VOID) ;
VOID func2(VOID) ;
VOID main(VOID)
{
func1() ;
func2() ;
g *= TWO ;
}
#define TWO 2
typedef void VOID ;
extern int g;
VOID func2(VOID) ;
VOID func1(VOID)
{
func2() ;
g += TWO ;
}
#define TWO 2
typedef void VOID ;
extern int g;
VOID func1(VOID) ;
VOID func2(VOID)
{
func1() ;
g -= TWO ;
}
file1.c file2.c file3.c
5
Modulization
 Split source code into separate files – Problem
– When you want to modify #define or typedef definitions
• You should modify all of source files
=> Solution : Use Header file
#define TWO 2
typedef void VOID ;
int g;
VOID func1(VOID) ;
VOID func2(VOID) ;
VOID main(VOID)
{
func1() ;
func2() ;
g *= TWO ;
}
#define TWO 2
typedef void VOID ;
extern int g;
VOID func2(VOID) ;
VOID func1(VOID)
{
func2() ;
g += TWO ;
}
#define TWO 2
typedef void VOID ;
extern int g;
VOID func1(VOID) ;
VOID func2(VOID)
{
func1() ;
g -= TWO ;
}
file1.c file2.c file3.c
6
Modulization
 Split source code into separate files
– Generally create one ~.h file for each ~.c file
– Content of ~.c
• Functions
• Definition and Declaration used the functions in the file
• #include header files necessary in the file
– Content of ~.h
• Extern definition of global variable accessed in the corresponding
~.c file
• Prototype of function defined in the corresponding ~.c file
• #include header files if necessary
7
Modulization
 Split source code into separate files
extern int g VOID func1(VOID) ; VOID func2(VOID) ;
int g;
VOID main(VOID)
{
func1() ;
func2() ;
g *= TWO ;
}
VOID func1(VOID)
{
func2() ;
g += TWO ;
}
VOID func2(VOID)
{
func1() ;
g -= TWO ;
}
file1.h file2.h file3.h
file2.c file3.cfile1.c
#define TWO 2
typedef void VOID ;
def.h
Modulization
 Split source code into separate files
– Include necessary ~.h files in ~.c and ~.h files
file1.h file2.h file3.h
extern int g
#include “def.h”
VOID func1(VOID) ;
#include “def.h”
VOID func2(VOID) ;
#include “def.h”
#include “file2.h”
#include “file3.h”
int g;
VOID main(VOID)
{
func1() ;
func2() ;
g *= TWO ;
}
#include “def.h”
#include “file1.h”
#include “file3.h”
VOID func1(VOID)
{
func2() ;
g += TWO ;
}
#include “def.h”
#include “file1.h”
#include “file2.h”
VOID func2(VOID)
{
func1() ;
g -= TWO ;
}
def.h
#define TWO 2
typedef void VOID ;
file2.c file3.cfile1.c 8
Conditional Compilation
 Problem with relation of header files
– Some header files are included more than once
• Cause overlapped definitions
– Solve with conditional compilation!
file1.h file2.h file2.h
file1.c file2.c file3.c
def.h
#define TWO 2
typedef void VOID ;
9
def.h is included twice
“TWO” is defined twice
Conditional Compilation
 Conditional compilation based on #ifndef, #endif
– Place all of content of header file between #ifndef and #endif
– Insert #define UNIQUE_NAME
10
11
Conditional Compilation
#ifndef _FILE1_H_
#define _FILE1_H_
extern int g
#endif
#ifndef _FILE2_H_
#define _FILE2_H_
#include “def.h”
VOID func1(VOID) ;
#endif
#ifndef _FILE3_H_
#defien _FILE3_H_
#include “def.h”
VOID func2(VOID) ;
#endif
#include “def.h”
#include “file2.h”
#include “file3.h”
int g;
VOID main(VOID)
{
func1() ;
func2() ;
g *= TWO ;
}
#include “def.h”
#include “file1.h”
#include “file3.h”
VOID func1(VOID)
{
func2() ;
g += TWO ;
}
#include “def.h”
#include “file1.h”
#include “file2.h”
VOID func2(VOID)
{
func1() ;
g -= TWO ;
}
#ifndef _DEF_H_
#define _DEF_H_
#define TWO 2
typedef void VOID ;
#endif
file2.c file3.cfile1.c
file1.h file2.h file3.hdef.h
12
#ifndef _FILE1_H_
#define _FILE1_H_
extern int g
#endif
#ifndef _FILE2_H_
#define _FILE2_H_
#include “def.h”
VOID func1(VOID) ;
#endif
#ifndef _FILE3_H_
#defien _FILE3_H_
#include “def.h”
VOID func2(VOID) ;
#endif
#include “def.h”
#include “file2.h”
#include “file3.h”
int g;
VOID main(VOID)
{
func1() ;
func2() ;
g *= TWO ;
}
#include “def.h”
#include “file1.h”
#include “file3.h”
static int g1 ;
VOID func1(VOID)
{
func2() ;
g += TWO ;
}
static VOID sfunc1(VOID)
{
}
#include “def.h”
#include “file1.h”
#include “file2.h”
static int g2 ;
VOID func2(VOID)
{
func1() ;
g -= TWO ;
}
static VOID sfunc2(VOID)
{
}
#ifndef _DEF_H_
#define _DEF_H_
#define TWO 2
typedef void VOID ;
#endif
file2.c file3.cfile1.c
file1.h file2.h file3.hdef.h

More Related Content

PDF
Code as Data workshop: Using source{d} Engine to extract insights from git re...
PPTX
Basic unix
PDF
GIT: Content-addressable filesystem and Version Control System
PPTX
Git Memento of basic commands
PPT
FFMPEG on android
KEY
Hachioji.pm in Machida の LT
PDF
Doing Horrible Things with DNS - Web Directions South
PDF
GTALUG Short Talk On Mercurial
Code as Data workshop: Using source{d} Engine to extract insights from git re...
Basic unix
GIT: Content-addressable filesystem and Version Control System
Git Memento of basic commands
FFMPEG on android
Hachioji.pm in Machida の LT
Doing Horrible Things with DNS - Web Directions South
GTALUG Short Talk On Mercurial

What's hot (16)

PDF
Cpp lab 13_pres
PPTX
File management
PDF
Unix commands
PPT
390a gitintro 12au
PDF
The Ring programming language version 1.5.1 book - Part 14 of 180
DOC
PDF
Packet crafting of2013
PDF
3.1.a linux commands reference
PDF
Golang execution modes
PPTX
lec6
DOC
PPTX
Cscope and ctags
PDF
NoSQL Couchbase Lite & BigData HPCC Systems
PPTX
sphinx-i18n — The True Story
PDF
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
PDF
Linux fundamental - Chap 09 pkg
Cpp lab 13_pres
File management
Unix commands
390a gitintro 12au
The Ring programming language version 1.5.1 book - Part 14 of 180
Packet crafting of2013
3.1.a linux commands reference
Golang execution modes
lec6
Cscope and ctags
NoSQL Couchbase Lite & BigData HPCC Systems
sphinx-i18n — The True Story
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
Linux fundamental - Chap 09 pkg
Ad

Viewers also liked (8)

PDF
14. fiile io
PDF
9. pointer, pointer & function
PDF
15 2. arguement passing to main
PDF
15 3. modulization
PPTX
Function pointer
PDF
13. structure
PPTX
Data structure lecture 1
PPTX
Pointers in C Programming
14. fiile io
9. pointer, pointer & function
15 2. arguement passing to main
15 3. modulization
Function pointer
13. structure
Data structure lecture 1
Pointers in C Programming
Ad

Similar to 15 3. modulization (20)

PDF
The beautyandthebeast phpbat2010
PPS
C programming session 11
PDF
Bento lunch talk
DOC
Lex tool manual
PDF
Devops for beginners
PDF
Do + ldo for developers(full)
PPTX
Reproducible Computational Research in R
PDF
The Linux Command Cheat Sheet
PPTX
GIT & COMPOSER __BASIC_git git git git.pptx
PDF
Programming in Linux Environment
PDF
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
PDF
Git 101 Workshop
PDF
Basic shell commands by Jeremy Sanders
PPTX
Topic - File operation.pptx
PPTX
pre processor and file handling in c language ppt
PPTX
Unit_V_Files handling in c programming language.pptx
PDF
Quick Guide with Linux Command Line
PDF
Happy Go Programming Part 1
The beautyandthebeast phpbat2010
C programming session 11
Bento lunch talk
Lex tool manual
Devops for beginners
Do + ldo for developers(full)
Reproducible Computational Research in R
The Linux Command Cheat Sheet
GIT & COMPOSER __BASIC_git git git git.pptx
Programming in Linux Environment
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Git 101 Workshop
Basic shell commands by Jeremy Sanders
Topic - File operation.pptx
pre processor and file handling in c language ppt
Unit_V_Files handling in c programming language.pptx
Quick Guide with Linux Command Line
Happy Go Programming Part 1

More from 웅식 전 (20)

PDF
12 2. dynamic allocation
PDF
12 1. multi-dimensional array
PDF
11. array & pointer
PDF
10. pointer & function
PDF
9. pointer
PDF
7. variable scope rule,-storage_class
PDF
6. function
PDF
5 2. string processing
PDF
5 1. character processing
PDF
15 1. enumeration, typedef
PDF
4. loop
PDF
3 2. if statement
PDF
3 1. preprocessor, math, stdlib
PDF
2 3. standard io
PDF
2 2. operators
PDF
2 1. variables & data types
PDF
Goorm ide 교육용버전 for skku(학생)
PDF
구름 기본 소개자료
PDF
Goorm ide 소개 슬라이드(교육용 버전)
PDF
W14 chap13
12 2. dynamic allocation
12 1. multi-dimensional array
11. array & pointer
10. pointer & function
9. pointer
7. variable scope rule,-storage_class
6. function
5 2. string processing
5 1. character processing
15 1. enumeration, typedef
4. loop
3 2. if statement
3 1. preprocessor, math, stdlib
2 3. standard io
2 2. operators
2 1. variables & data types
Goorm ide 교육용버전 for skku(학생)
구름 기본 소개자료
Goorm ide 소개 슬라이드(교육용 버전)
W14 chap13

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
SOPHOS-XG Firewall Administrator PPT.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...

15 3. modulization

  • 2. Developing a Large Program  Developing a large Program – We can split source codes into several ~. h and ~.c files – There are many merits of several small files instead of one big file • Easy to maintain source codes • Easy to co-work with other programmers • Save time when compiling: You can just compile ~.c files which are modified not all of source codes. 2
  • 3. 3 Modulization  Split source code into separate files #define TWO 2 typedef void VOID ; int g; VOID func1(VOID) ; VOID func2(VOID ) ; VOID main(VOID ) { func1() ; func2() ; g *= TWO ; } file.c VOID func1(VOID ) { func2() ; g += TWO ; } VOID func2(VOID ) { func1() ; g -= TWO ; } To be written by friend 1 To be written by friend 2 To be written by me
  • 4. 4 Modulization  Split source code into separate files – Make ~.c files for each function – Add #define, declaration, function prototypes, extern objects Prototype of Functions #define TWO 2 typedef void VOID ; int g; VOID func1(VOID) ; VOID func2(VOID) ; VOID main(VOID) { func1() ; func2() ; g *= TWO ; } #define TWO 2 typedef void VOID ; extern int g; VOID func2(VOID) ; VOID func1(VOID) { func2() ; g += TWO ; } #define TWO 2 typedef void VOID ; extern int g; VOID func1(VOID) ; VOID func2(VOID) { func1() ; g -= TWO ; } file1.c file2.c file3.c
  • 5. 5 Modulization  Split source code into separate files – Problem – When you want to modify #define or typedef definitions • You should modify all of source files => Solution : Use Header file #define TWO 2 typedef void VOID ; int g; VOID func1(VOID) ; VOID func2(VOID) ; VOID main(VOID) { func1() ; func2() ; g *= TWO ; } #define TWO 2 typedef void VOID ; extern int g; VOID func2(VOID) ; VOID func1(VOID) { func2() ; g += TWO ; } #define TWO 2 typedef void VOID ; extern int g; VOID func1(VOID) ; VOID func2(VOID) { func1() ; g -= TWO ; } file1.c file2.c file3.c
  • 6. 6 Modulization  Split source code into separate files – Generally create one ~.h file for each ~.c file – Content of ~.c • Functions • Definition and Declaration used the functions in the file • #include header files necessary in the file – Content of ~.h • Extern definition of global variable accessed in the corresponding ~.c file • Prototype of function defined in the corresponding ~.c file • #include header files if necessary
  • 7. 7 Modulization  Split source code into separate files extern int g VOID func1(VOID) ; VOID func2(VOID) ; int g; VOID main(VOID) { func1() ; func2() ; g *= TWO ; } VOID func1(VOID) { func2() ; g += TWO ; } VOID func2(VOID) { func1() ; g -= TWO ; } file1.h file2.h file3.h file2.c file3.cfile1.c #define TWO 2 typedef void VOID ; def.h
  • 8. Modulization  Split source code into separate files – Include necessary ~.h files in ~.c and ~.h files file1.h file2.h file3.h extern int g #include “def.h” VOID func1(VOID) ; #include “def.h” VOID func2(VOID) ; #include “def.h” #include “file2.h” #include “file3.h” int g; VOID main(VOID) { func1() ; func2() ; g *= TWO ; } #include “def.h” #include “file1.h” #include “file3.h” VOID func1(VOID) { func2() ; g += TWO ; } #include “def.h” #include “file1.h” #include “file2.h” VOID func2(VOID) { func1() ; g -= TWO ; } def.h #define TWO 2 typedef void VOID ; file2.c file3.cfile1.c 8
  • 9. Conditional Compilation  Problem with relation of header files – Some header files are included more than once • Cause overlapped definitions – Solve with conditional compilation! file1.h file2.h file2.h file1.c file2.c file3.c def.h #define TWO 2 typedef void VOID ; 9 def.h is included twice “TWO” is defined twice
  • 10. Conditional Compilation  Conditional compilation based on #ifndef, #endif – Place all of content of header file between #ifndef and #endif – Insert #define UNIQUE_NAME 10
  • 11. 11 Conditional Compilation #ifndef _FILE1_H_ #define _FILE1_H_ extern int g #endif #ifndef _FILE2_H_ #define _FILE2_H_ #include “def.h” VOID func1(VOID) ; #endif #ifndef _FILE3_H_ #defien _FILE3_H_ #include “def.h” VOID func2(VOID) ; #endif #include “def.h” #include “file2.h” #include “file3.h” int g; VOID main(VOID) { func1() ; func2() ; g *= TWO ; } #include “def.h” #include “file1.h” #include “file3.h” VOID func1(VOID) { func2() ; g += TWO ; } #include “def.h” #include “file1.h” #include “file2.h” VOID func2(VOID) { func1() ; g -= TWO ; } #ifndef _DEF_H_ #define _DEF_H_ #define TWO 2 typedef void VOID ; #endif file2.c file3.cfile1.c file1.h file2.h file3.hdef.h
  • 12. 12 #ifndef _FILE1_H_ #define _FILE1_H_ extern int g #endif #ifndef _FILE2_H_ #define _FILE2_H_ #include “def.h” VOID func1(VOID) ; #endif #ifndef _FILE3_H_ #defien _FILE3_H_ #include “def.h” VOID func2(VOID) ; #endif #include “def.h” #include “file2.h” #include “file3.h” int g; VOID main(VOID) { func1() ; func2() ; g *= TWO ; } #include “def.h” #include “file1.h” #include “file3.h” static int g1 ; VOID func1(VOID) { func2() ; g += TWO ; } static VOID sfunc1(VOID) { } #include “def.h” #include “file1.h” #include “file2.h” static int g2 ; VOID func2(VOID) { func1() ; g -= TWO ; } static VOID sfunc2(VOID) { } #ifndef _DEF_H_ #define _DEF_H_ #define TWO 2 typedef void VOID ; #endif file2.c file3.cfile1.c file1.h file2.h file3.hdef.h