SlideShare a Scribd company logo
1 of 46
Download to read offline
C_Programming
Part 6
ENG. KEROLES SHENOUDA
1
C – Preprocessor directives
 Before a C program is compiled in a compiler, source code is processed by a
program called preprocessor. This process is called preprocessing.
 Commands used in preprocessor are called preprocessor directives and they
begin with “#” symbol.
2
A program in C language involves into
different processes
3
DIFFERENCE BETWEEN COMPILERS VS
INTERPRETERS IN C LANGUAGE?
Compilers Interpreters
Compiler reads the entire source code of the
program and converts it into binary
code. This process is called compilation.
Binary code is also referred as machine
code, executable, and object code.
Interpreter reads the program source code
one line at a time and executing that
line. This process is called interpretation.
Program speed is fast. Program speed is slow.
One time execution.
Example: C, C++
Interpretation occurs at every
line of the program.
Example: BASIC
4
list of preprocessor directives that C
programming language offers.
Preprocessor Syntax/Description
Macro
Syntax: #define
This macro defines constant value and can be any of
the basic data types.
Header file inclusion
Syntax: #include <file_name>
The source code of the file “file_name” is included in
the main program at the specified place.
Conditional compilation
Syntax: #ifdef, #endif, #if, #else, #ifndef
Set of commands are included or excluded in source
program before compilation with respect to the
condition.
Other directives
Syntax: #undef, #pragma
#undef is used to undefine a defined macro variable.
#Pragma is used to call a function before and after
main function in a C program.
5
Macro 6
Sometimes programmers repeat the writing of the same code segment all over the program.
Sometimes the code segment is repeated exactly another times it repeated with some
changes.
If the repeated code size is large, it is preferable to define a function for this code. If the
repeated code size is small Macros may be the best choice. Macros also do not affect the
execution speed because there is no parameter passing in Macros.
Macro 7
Macros
Is
Text Replacement
Macro
How To see the .i file (precompiled file )
8
First we will
Modify the Project Settings
To Compile not internally
But from external Makefile
Macro
How To see the .i file (precompiled file )
9
Second
Run the Build and Then you will
Find a Makefile will be created
Automatically
Kindly Note You will get full Knowledge
on Makefile on the Next Sessiones
Macro
How To see the .i file (precompiled file )
10
Third: This Makefile
generated
Automatically at
Every time you build
So if we want to
Modify on it without
any change
Do the Following
Unmark it
Macro
How To see the .i file (precompiled file )
11
Fourth : we will add a
commands to generate
.i and .s
By our hand on the
Makefile
Macro
How To see the .i file (precompiled file )
12
Fifth:
Rebuild again
You will see the files
Generated
We can see the precompiled file .i
have a text replacement for MACRO
13
Now are you agree with me
The #define directives define the identifier as a
macro, that is they instruct the compiler to
replace all successive occurrences of
identifier with replacement-list
Another
Example
14
Another
Example
15
__VA_ARGS__
 Version (3) of the #define directive defines a function-like macro with variable
number of arguments. The additional arguments can be accessed using
__VA_ARGS__ identifier, which is then replaced with arguments, supplied with
the identifier to be replaced.
 Version (4) of the #define directive defines a function-like macro with variable
number of arguments, but no regular arguments. The arguments can be
accessed only with __VA_ARGS__ identifier, which is then replaced with
arguments, supplied with identifier to be replaced.
 A ## operator between any two successive identifiers in the replacement-list
runs parameter replacement on the two identifiers and then concatenates the
result
16
17
18
Think in Depth
how to overcome on this error without
remove Dprintf from main
19
Two errors
Think in Depth
how to overcome on this error without
remove Dprintf from main
20
# Convert to string
#undef directive
 The #undef directive undefines the identifier, that is it cancels the previous
definition of the identifier by #define directive. If the identifier does not have
an associated macro, the directive is ignored.
21
EXAMPLE PROGRAM FOR UNDEF IN C
LANGUAGE:
22
Think In Depth
Try to make function factory and use it
by Macro
 Use one macro to create two Functions, one
responsible on multiply input argument to 4
and the other to multiply one input argument
to 2.
 The first function name will be
fun_quadruple(int x)
 The Second one will be fun_double (int x)
23
24
25
Predefined macros
The following macro names are predefined in any translation unit:
26
27
28
Macros ==Text Replacement
Predefined macros
__VA_ARGS__ & # & ##
Conditional compilation
Syntax: #ifdef, #endif, #if,
#else, #ifndef
Set of commands are included or excluded
in source program before compilation with
respect to the condition.
29
EXAMPLE PROGRAM FOR #IFDEF,
#ELSE AND #ENDIF IN C:
 “#ifdef” directive checks whether particular macro is defined or not.
If it is defined, “If” clause statements are included in source file.
 Otherwise, “else” clause statements are included in source file for compilation and execution.
30
EXAMPLE PROGRAM FOR #IFDEF,
#ELSE AND #ENDIF IN C:
31
EXAMPLE PROGRAM FOR #IFDEF,
#ELSE AND #ENDIF IN C:
32
EXAMPLE PROGRAM FOR #IFNDEF AND
#ENDIF IN C:
 #ifndef exactly acts as reverse as #ifdef directive. If particular
macro is not defined, “If” clause statements are included in source file.
 Otherwise, else clause statements are included in source file for compilation
and execution.
33
EXAMPLE PROGRAM FOR #IFNDEF AND
#ENDIF IN C:
34
EXAMPLE PROGRAM FOR #IFNDEF AND
#ENDIF IN C:
35
EXAMPLE PROGRAM FOR #IF, #ELSE
AND #ENDIF IN C:
“If” clause statement is included in source file if given condition is true.
 Otherwise, else clause statement is included in source file for compilation and
execution.
36
37
Pragma directive in c
 Pragma is implementation specific directive i.e each pragma directive has different
implementation rule and use .
 There are many type of pragma directive and varies from one compiler to another
compiler .
 If compiler does not recognize particular pragma the it simply ignore that
pragma statement without showing any error message and execute the
whole program assuming this pragma statement is not present.
38
Pragma
directive in
c
39
We will take
 #pragma startup
 #pragma exit
40
What is #pragma startup and #pragma
exit in c programming language?
 #pragma startup [priority]
 #pragma exit [priority]
 Where priority is optional integral number.
 For user priority varies from 64 to 255
 For c libraries priority varies from 0 to 63
 Default priority is 100.
41
What is #pragma startup and #pragma
exit in c programming language?
 pragma startup always execute the function before the main function
pragma exit always execute the function after the main function.Function
declaration of must be before startup and exit pragma directives and function must
not take any argument and return void. If more than one startup directive then
priority decides which will execute first.
 startup:
 Lower value: higher priority i.e. functions will execute first. If more than one exit directive
then priority decides which will execute first.
 exit:
 Higher value: higher priority i.e. functions will execute first. For example
42
43
#pragma
startup/exit ...
is not
supported in
gcc.
 In gcc and clang, you should use
__attribute__((constructor)) and
__attribute__((destructor))
instead.
44
45
Quiz: Think how to write a
code can be
Removed or added to the
Embedded C Program and
Responsible on print Debug
with Details
References 46
 The Case for Learning C as Your First Programming Language
 A Tutorial on Data Representation
 std::printf, std::fprintf, std::sprintf, std::snprintf…..
 C Programming for Engineers, Dr. Mohamed Sobh
 C programming expert.
 fresh2refresh.com/c-programming
 C programming Interview questions and answers
 C – Preprocessor directives

More Related Content

What's hot (20)

Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
C programming part2
C programming part2C programming part2
C programming part2
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Session 8,9 PCI Express
Session 8,9 PCI ExpressSession 8,9 PCI Express
Session 8,9 PCI Express
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 

Viewers also liked (20)

C programming part2
C programming part2C programming part2
C programming part2
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Microcontroller part 7_v1
Microcontroller part 7_v1Microcontroller part 7_v1
Microcontroller part 7_v1
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Microcontroller part 9_v1
Microcontroller part 9_v1Microcontroller part 9_v1
Microcontroller part 9_v1
 
Microcontroller part 8_v1
Microcontroller part 8_v1Microcontroller part 8_v1
Microcontroller part 8_v1
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Microcontroller part 6_v1
Microcontroller part 6_v1Microcontroller part 6_v1
Microcontroller part 6_v1
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
Homework 2
Homework 2Homework 2
Homework 2
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
C programming part4
C programming part4C programming part4
C programming part4
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 

Similar to C programming session6

Similar to C programming session6 (20)

Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 
1 - Preprocessor.pptx
1 - Preprocessor.pptx1 - Preprocessor.pptx
1 - Preprocessor.pptx
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Introduction to Preprocessors
Introduction to PreprocessorsIntroduction to Preprocessors
Introduction to Preprocessors
 
Preprocesser in c
Preprocesser in cPreprocesser in c
Preprocesser in c
 
Preprocessor.pptx
Preprocessor.pptxPreprocessor.pptx
Preprocessor.pptx
 
pre processor directives in C
pre processor directives in Cpre processor directives in C
pre processor directives in C
 
Preprocesser in c++ by thanveer danish
Preprocesser in c++ by thanveer danishPreprocesser in c++ by thanveer danish
Preprocesser in c++ by thanveer danish
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 

More from Keroles karam khalil (15)

Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
Notes part7
Notes part7Notes part7
Notes part7
 
Homework 5
Homework 5Homework 5
Homework 5
 
Notes part6
Notes part6Notes part6
Notes part6
 
Homework 4 solution
Homework 4 solutionHomework 4 solution
Homework 4 solution
 
Notes part5
Notes part5Notes part5
Notes part5
 
Homework 4
Homework 4Homework 4
Homework 4
 
Homework 3 solution
Homework 3 solutionHomework 3 solution
Homework 3 solution
 
C programming session5
C programming  session5C programming  session5
C programming session5
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

C programming session6

  • 2. C – Preprocessor directives  Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.  Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol. 2
  • 3. A program in C language involves into different processes 3
  • 4. DIFFERENCE BETWEEN COMPILERS VS INTERPRETERS IN C LANGUAGE? Compilers Interpreters Compiler reads the entire source code of the program and converts it into binary code. This process is called compilation. Binary code is also referred as machine code, executable, and object code. Interpreter reads the program source code one line at a time and executing that line. This process is called interpretation. Program speed is fast. Program speed is slow. One time execution. Example: C, C++ Interpretation occurs at every line of the program. Example: BASIC 4
  • 5. list of preprocessor directives that C programming language offers. Preprocessor Syntax/Description Macro Syntax: #define This macro defines constant value and can be any of the basic data types. Header file inclusion Syntax: #include <file_name> The source code of the file “file_name” is included in the main program at the specified place. Conditional compilation Syntax: #ifdef, #endif, #if, #else, #ifndef Set of commands are included or excluded in source program before compilation with respect to the condition. Other directives Syntax: #undef, #pragma #undef is used to undefine a defined macro variable. #Pragma is used to call a function before and after main function in a C program. 5
  • 6. Macro 6 Sometimes programmers repeat the writing of the same code segment all over the program. Sometimes the code segment is repeated exactly another times it repeated with some changes. If the repeated code size is large, it is preferable to define a function for this code. If the repeated code size is small Macros may be the best choice. Macros also do not affect the execution speed because there is no parameter passing in Macros.
  • 8. Macro How To see the .i file (precompiled file ) 8 First we will Modify the Project Settings To Compile not internally But from external Makefile
  • 9. Macro How To see the .i file (precompiled file ) 9 Second Run the Build and Then you will Find a Makefile will be created Automatically Kindly Note You will get full Knowledge on Makefile on the Next Sessiones
  • 10. Macro How To see the .i file (precompiled file ) 10 Third: This Makefile generated Automatically at Every time you build So if we want to Modify on it without any change Do the Following Unmark it
  • 11. Macro How To see the .i file (precompiled file ) 11 Fourth : we will add a commands to generate .i and .s By our hand on the Makefile
  • 12. Macro How To see the .i file (precompiled file ) 12 Fifth: Rebuild again You will see the files Generated
  • 13. We can see the precompiled file .i have a text replacement for MACRO 13 Now are you agree with me The #define directives define the identifier as a macro, that is they instruct the compiler to replace all successive occurrences of identifier with replacement-list
  • 16. __VA_ARGS__  Version (3) of the #define directive defines a function-like macro with variable number of arguments. The additional arguments can be accessed using __VA_ARGS__ identifier, which is then replaced with arguments, supplied with the identifier to be replaced.  Version (4) of the #define directive defines a function-like macro with variable number of arguments, but no regular arguments. The arguments can be accessed only with __VA_ARGS__ identifier, which is then replaced with arguments, supplied with identifier to be replaced.  A ## operator between any two successive identifiers in the replacement-list runs parameter replacement on the two identifiers and then concatenates the result 16
  • 17. 17
  • 18. 18
  • 19. Think in Depth how to overcome on this error without remove Dprintf from main 19 Two errors
  • 20. Think in Depth how to overcome on this error without remove Dprintf from main 20 # Convert to string
  • 21. #undef directive  The #undef directive undefines the identifier, that is it cancels the previous definition of the identifier by #define directive. If the identifier does not have an associated macro, the directive is ignored. 21
  • 22. EXAMPLE PROGRAM FOR UNDEF IN C LANGUAGE: 22
  • 23. Think In Depth Try to make function factory and use it by Macro  Use one macro to create two Functions, one responsible on multiply input argument to 4 and the other to multiply one input argument to 2.  The first function name will be fun_quadruple(int x)  The Second one will be fun_double (int x) 23
  • 24. 24
  • 25. 25
  • 26. Predefined macros The following macro names are predefined in any translation unit: 26
  • 27. 27
  • 28. 28 Macros ==Text Replacement Predefined macros __VA_ARGS__ & # & ##
  • 29. Conditional compilation Syntax: #ifdef, #endif, #if, #else, #ifndef Set of commands are included or excluded in source program before compilation with respect to the condition. 29
  • 30. EXAMPLE PROGRAM FOR #IFDEF, #ELSE AND #ENDIF IN C:  “#ifdef” directive checks whether particular macro is defined or not. If it is defined, “If” clause statements are included in source file.  Otherwise, “else” clause statements are included in source file for compilation and execution. 30
  • 31. EXAMPLE PROGRAM FOR #IFDEF, #ELSE AND #ENDIF IN C: 31
  • 32. EXAMPLE PROGRAM FOR #IFDEF, #ELSE AND #ENDIF IN C: 32
  • 33. EXAMPLE PROGRAM FOR #IFNDEF AND #ENDIF IN C:  #ifndef exactly acts as reverse as #ifdef directive. If particular macro is not defined, “If” clause statements are included in source file.  Otherwise, else clause statements are included in source file for compilation and execution. 33
  • 34. EXAMPLE PROGRAM FOR #IFNDEF AND #ENDIF IN C: 34
  • 35. EXAMPLE PROGRAM FOR #IFNDEF AND #ENDIF IN C: 35
  • 36. EXAMPLE PROGRAM FOR #IF, #ELSE AND #ENDIF IN C: “If” clause statement is included in source file if given condition is true.  Otherwise, else clause statement is included in source file for compilation and execution. 36
  • 37. 37
  • 38. Pragma directive in c  Pragma is implementation specific directive i.e each pragma directive has different implementation rule and use .  There are many type of pragma directive and varies from one compiler to another compiler .  If compiler does not recognize particular pragma the it simply ignore that pragma statement without showing any error message and execute the whole program assuming this pragma statement is not present. 38
  • 40. We will take  #pragma startup  #pragma exit 40
  • 41. What is #pragma startup and #pragma exit in c programming language?  #pragma startup [priority]  #pragma exit [priority]  Where priority is optional integral number.  For user priority varies from 64 to 255  For c libraries priority varies from 0 to 63  Default priority is 100. 41
  • 42. What is #pragma startup and #pragma exit in c programming language?  pragma startup always execute the function before the main function pragma exit always execute the function after the main function.Function declaration of must be before startup and exit pragma directives and function must not take any argument and return void. If more than one startup directive then priority decides which will execute first.  startup:  Lower value: higher priority i.e. functions will execute first. If more than one exit directive then priority decides which will execute first.  exit:  Higher value: higher priority i.e. functions will execute first. For example 42
  • 43. 43
  • 44. #pragma startup/exit ... is not supported in gcc.  In gcc and clang, you should use __attribute__((constructor)) and __attribute__((destructor)) instead. 44
  • 45. 45 Quiz: Think how to write a code can be Removed or added to the Embedded C Program and Responsible on print Debug with Details
  • 46. References 46  The Case for Learning C as Your First Programming Language  A Tutorial on Data Representation  std::printf, std::fprintf, std::sprintf, std::snprintf…..  C Programming for Engineers, Dr. Mohamed Sobh  C programming expert.  fresh2refresh.com/c-programming  C programming Interview questions and answers  C – Preprocessor directives