SlideShare a Scribd company logo
1 of 10
The Preprocessor
• C# defines several preprocessor directives,
which affect the way that your program’s
source file is interpreted by the compiler.
• The term preprocessor directive comes from
the fact that these instructions were
traditionally handled by a separate compilation
phase called the preprocessor.
• All preprocessor directives begin with a # sign.
In addition, each preprocessor directive must be
on its own line.
• Today’s modern compiler technology no longer
requires a separate preprocessing stage to
handle the directives, but the name has stuck.
C# defines the following preprocessor directives:
• #define
• #endif

#elif
#line

#else
#warning

• #endregion

#error

#if

• #pragma

#region

#undef
• #define: The #define directive defines a
character sequence called a symbol.
• The existence or nonexistence of a symbol can
be determined by #if or #elif and is used to
control compilation.
• Here is the general form for # define :
#define symbol
• Notice that there is no semicolon in this
statement.
• In C/C++ you can use #define to perform
textual substitutions, such as defining a name
for a value, and to create function-like
macros. C# does not support these uses of
#define.
• In C#, #define is used only to define a symbol.
• For example, to define the symbol
EXPERIMENTAL, use this directive:
• #define EXPERIMENTAL
• #if and #endif: The #if and #endif directives
enable conditional compilation of a sequence
of code based upon whether an expression
involving one or more symbols evaluates to
true.
• A symbol is true if it has been defined. It is
false otherwise.
• Thus, if a symbol has been defined by a
#define directive, it will evaluate as true.
#define EXPERIMENTAL
using System;
class Test {
static void Main()
{
#if EXPERIMENTAL
Console.WriteLine("Compiled for experimental version.");

#else
Console.WriteLine("Compiled for release.");

#endif
#if EXPERIMENTAL && TRIAL
Console.WriteLine("Testing experimental trial version.");

#else
Console.WriteLine("Not experimental trial version.");

#endif
Console.WriteLine("This is in all versions.");
}
}
• #undef: The #undef directive removes a
previously defined symbol. That is, it
“undefines” a symbol.
• #error: The #error directive forces the
compiler to stop compilation. It is used for
debugging.
• #warning: The #warning directive is similar to
#error , except that a warning rather than an
error is produced.
• #undef: The #undef directive removes a
previously defined symbol. That is, it
“undefines” a symbol.
• #error: The #error directive forces the
compiler to stop compilation. It is used for
debugging.
• #warning: The #warning directive is similar to
#error , except that a warning rather than an
error is produced.

More Related Content

What's hot

Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
MeoRamos
 

What's hot (20)

Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in C
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
PhpSpec: practical introduction
PhpSpec: practical introductionPhpSpec: practical introduction
PhpSpec: practical introduction
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Include and define directives
Include and define directivesInclude and define directives
Include and define directives
 
Structure of C program
Structure of C programStructure of C program
Structure of C program
 
Decision making and loop in C#
Decision making and loop in C#Decision making and loop in C#
Decision making and loop in C#
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Notes part5
Notes part5Notes part5
Notes part5
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
 
Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7
 
C++
C++C++
C++
 
Codings Standards
Codings StandardsCodings Standards
Codings Standards
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
PHP coding tips and review guides
PHP coding tips and review guidesPHP coding tips and review guides
PHP coding tips and review guides
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 

Similar to Preprocessor

Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11
patcha535
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
Hector Garzo
 

Similar to Preprocessor (20)

C programming session6
C programming  session6C programming  session6
C programming session6
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 
Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
10control statement in c#
10control statement in c#10control statement in c#
10control statement in c#
 
1 - Preprocessor.pptx
1 - Preprocessor.pptx1 - Preprocessor.pptx
1 - Preprocessor.pptx
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
 
C programming
C programmingC programming
C programming
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net Framework
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
 
No comment
No commentNo comment
No comment
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C# language
C# languageC# language
C# language
 
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
 
Preprocesser in c
Preprocesser in cPreprocesser in c
Preprocesser in c
 

More from abhay singh (15)

Iso 27001
Iso 27001Iso 27001
Iso 27001
 
Web service
Web serviceWeb service
Web service
 
Unsafe
UnsafeUnsafe
Unsafe
 
Threading
ThreadingThreading
Threading
 
Networking and socket
Networking and socketNetworking and socket
Networking and socket
 
Namespace
NamespaceNamespace
Namespace
 
Inheritance
InheritanceInheritance
Inheritance
 
Generic
GenericGeneric
Generic
 
Gdi
GdiGdi
Gdi
 
Exception
ExceptionException
Exception
 
Delegate
DelegateDelegate
Delegate
 
Constructor
ConstructorConstructor
Constructor
 
Collection
CollectionCollection
Collection
 
Ado
AdoAdo
Ado
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Preprocessor

  • 2. • C# defines several preprocessor directives, which affect the way that your program’s source file is interpreted by the compiler. • The term preprocessor directive comes from the fact that these instructions were traditionally handled by a separate compilation phase called the preprocessor. • All preprocessor directives begin with a # sign. In addition, each preprocessor directive must be on its own line. • Today’s modern compiler technology no longer requires a separate preprocessing stage to handle the directives, but the name has stuck.
  • 3. C# defines the following preprocessor directives: • #define • #endif #elif #line #else #warning • #endregion #error #if • #pragma #region #undef
  • 4. • #define: The #define directive defines a character sequence called a symbol. • The existence or nonexistence of a symbol can be determined by #if or #elif and is used to control compilation. • Here is the general form for # define : #define symbol • Notice that there is no semicolon in this statement.
  • 5. • In C/C++ you can use #define to perform textual substitutions, such as defining a name for a value, and to create function-like macros. C# does not support these uses of #define. • In C#, #define is used only to define a symbol. • For example, to define the symbol EXPERIMENTAL, use this directive: • #define EXPERIMENTAL
  • 6. • #if and #endif: The #if and #endif directives enable conditional compilation of a sequence of code based upon whether an expression involving one or more symbols evaluates to true. • A symbol is true if it has been defined. It is false otherwise. • Thus, if a symbol has been defined by a #define directive, it will evaluate as true.
  • 7. #define EXPERIMENTAL using System; class Test { static void Main() { #if EXPERIMENTAL Console.WriteLine("Compiled for experimental version."); #else Console.WriteLine("Compiled for release."); #endif
  • 8. #if EXPERIMENTAL && TRIAL Console.WriteLine("Testing experimental trial version."); #else Console.WriteLine("Not experimental trial version."); #endif Console.WriteLine("This is in all versions."); } }
  • 9. • #undef: The #undef directive removes a previously defined symbol. That is, it “undefines” a symbol. • #error: The #error directive forces the compiler to stop compilation. It is used for debugging. • #warning: The #warning directive is similar to #error , except that a warning rather than an error is produced.
  • 10. • #undef: The #undef directive removes a previously defined symbol. That is, it “undefines” a symbol. • #error: The #error directive forces the compiler to stop compilation. It is used for debugging. • #warning: The #warning directive is similar to #error , except that a warning rather than an error is produced.