SlideShare a Scribd company logo
1 of 12
Download to read offline
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

What's hot

The Ring programming language version 1.5.1 book - Part 14 of 180
The Ring programming language version 1.5.1 book - Part 14 of 180The Ring programming language version 1.5.1 book - Part 14 of 180
The Ring programming language version 1.5.1 book - Part 14 of 180Mahmoud Samir Fayed
 
3.1.a linux commands reference
3.1.a linux commands reference3.1.a linux commands reference
3.1.a linux commands referenceAcácio Oliveira
 
Golang execution modes
Golang execution modesGolang execution modes
Golang execution modesTing-Li Chou
 
NoSQL Couchbase Lite & BigData HPCC Systems
NoSQL Couchbase Lite & BigData HPCC SystemsNoSQL Couchbase Lite & BigData HPCC Systems
NoSQL Couchbase Lite & BigData HPCC SystemsFujio Turner
 
sphinx-i18n — The True Story
sphinx-i18n — The True Storysphinx-i18n — The True Story
sphinx-i18n — The True StoryRobert Lehmann
 
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce Diane Mueller
 
Linux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkgLinux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkgKenny (netman)
 

What's hot (16)

Cpp lab 13_pres
Cpp lab 13_presCpp lab 13_pres
Cpp lab 13_pres
 
File management
File managementFile management
File management
 
Unix commands
Unix commandsUnix commands
Unix commands
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
The Ring programming language version 1.5.1 book - Part 14 of 180
The Ring programming language version 1.5.1 book - Part 14 of 180The Ring programming language version 1.5.1 book - Part 14 of 180
The Ring programming language version 1.5.1 book - Part 14 of 180
 
sss
ssssss
sss
 
Packet crafting of2013
Packet crafting of2013Packet crafting of2013
Packet crafting of2013
 
3.1.a linux commands reference
3.1.a linux commands reference3.1.a linux commands reference
3.1.a linux commands reference
 
Golang execution modes
Golang execution modesGolang execution modes
Golang execution modes
 
lec6
lec6lec6
lec6
 
Unix lab
Unix labUnix lab
Unix lab
 
Cscope and ctags
Cscope and ctagsCscope and ctags
Cscope and ctags
 
NoSQL Couchbase Lite & BigData HPCC Systems
NoSQL Couchbase Lite & BigData HPCC SystemsNoSQL Couchbase Lite & BigData HPCC Systems
NoSQL Couchbase Lite & BigData HPCC Systems
 
sphinx-i18n — The True Story
sphinx-i18n — The True Storysphinx-i18n — The True Story
sphinx-i18n — The True Story
 
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
 
Linux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkgLinux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkg
 

Viewers also liked

Viewers also liked (8)

14. fiile io
14. fiile io14. fiile io
14. fiile io
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
 
15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization
 
Function pointer
Function pointerFunction pointer
Function pointer
 
13. structure
13. structure13. structure
13. structure
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 

Similar to 15 3. modulization

The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010Bastian Feder
 
C programming session 11
C programming session 11C programming session 11
C programming session 11AjayBahoriya
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Devops for beginners
Devops for beginnersDevops for beginners
Devops for beginnersVivek Parihar
 
Do + ldo for developers(full)
Do + ldo for developers(full)Do + ldo for developers(full)
Do + ldo for developers(full)Andrii Podanenko
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in RSamuel Bosch
 
The Linux Command Cheat Sheet
The Linux Command Cheat SheetThe Linux Command Cheat Sheet
The Linux Command Cheat SheetTola LENG
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux EnvironmentDongho Kang
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Ahmed El-Arabawy
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 WorkshopJoy Seng
 
Basic shell commands by Jeremy Sanders
Basic shell commands by Jeremy SandersBasic shell commands by Jeremy Sanders
Basic shell commands by Jeremy SandersDevanand Gehlot
 
Topic - File operation.pptx
Topic - File operation.pptxTopic - File operation.pptx
Topic - File operation.pptxAdnan al-emran
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command LineAnuchit Chalothorn
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1Lin Yo-An
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Delphi L05 Files and Dialogs
Delphi L05 Files and DialogsDelphi L05 Files and Dialogs
Delphi L05 Files and DialogsMohammad Shaker
 

Similar to 15 3. modulization (20)

The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010
 
C programming session 11
C programming session 11C programming session 11
C programming session 11
 
Bento lunch talk
Bento   lunch talkBento   lunch talk
Bento lunch talk
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Devops for beginners
Devops for beginnersDevops for beginners
Devops for beginners
 
Do + ldo for developers(full)
Do + ldo for developers(full)Do + ldo for developers(full)
Do + ldo for developers(full)
 
File operations in c
File operations in cFile operations in c
File operations in c
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
The Linux Command Cheat Sheet
The Linux Command Cheat SheetThe Linux Command Cheat Sheet
The Linux Command Cheat Sheet
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
 
Basic shell commands by Jeremy Sanders
Basic shell commands by Jeremy SandersBasic shell commands by Jeremy Sanders
Basic shell commands by Jeremy Sanders
 
Topic - File operation.pptx
Topic - File operation.pptxTopic - File operation.pptx
Topic - File operation.pptx
 
Linux
LinuxLinux
Linux
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command Line
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Delphi L05 Files and Dialogs
Delphi L05 Files and DialogsDelphi L05 Files and Dialogs
Delphi L05 Files and Dialogs
 

More from 웅식 전

12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation웅식 전
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array웅식 전
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer웅식 전
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function웅식 전
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class웅식 전
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing웅식 전
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing웅식 전
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef웅식 전
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement웅식 전
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io웅식 전
 
2 2. operators
2 2. operators2 2. operators
2 2. operators웅식 전
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types웅식 전
 
Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)웅식 전
 
구름 기본 소개자료
구름 기본 소개자료구름 기본 소개자료
구름 기본 소개자료웅식 전
 
Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)웅식 전
 

More from 웅식 전 (20)

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

Recently uploaded

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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