Preprocessor
lượt xem 1
download
Preprocessor presents about Preprocessing; Preprocessor directives; Basic syntax; Creating symbols; Compiler option; Symbol states; Removing symbols; Testing symbol; Preprocessing expression; Controlling line number and file name; Diagnostic directives;...
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Preprocessor
- Preprocessor
- Objectives • Describe preprocessor commands – syntax – common use 2
- Preprocessing • C# offers preprocessing – first stage of translation – performed by the compiler – evaluates preprocessor directives • The term preprocessor is historical – comes from the C/C++ tradition – preprocessor was separate program that ran before compiler 3
- Preprocessor directives • Available preprocessor directives – #define – #undef – #if – #else – #elif – #endif – #line – #warning – #error – #region – #endregion 4
- Basic syntax • Preprocessing directive must be only statement on a line – leading whitespace ok static void Main() { leading whitespace #if Logging ... } 5
- Creating symbols • Can create conditional compilation symbol – syntax: #define followed by symbol – must go at beginning of file – applies only to that file – ok to define same symbol more than once create #define Logging symbol ... 6
- Compiler option • Can use compiler option to create symbol – syntax: /define: followed by symbol – applies to all files in compilation command use compiler C:\> csc /define:Logging MyApplication.cs option 7
- Symbol states • Symbols have only two states – defined – undefined • States correspond to Boolean values – defined = true – undefined = false symbol now defined, #define Logging has value true ... 8
- Removing symbols • Can remove symbol definition – syntax: #undef followed by symbol – must go at beginning of file – applies only to that file – ok if symbol is not defined – useful to turn off symbol created with compiler option remove #undef Logging symbol ... 9
- Testing symbol • Several options for testing symbol status – #if ... #endif – #if ... #else ... #endif – #if ... #elif ... #endif • Boolean value of symbol used in test – true = guarded code passed to next stage of compilation – false = guarded code eliminated static void Main() { #if Logging code included only Console.WriteLine("enter main"); if symbol defined #endif } 10
- Preprocessing expression • Symbol test can be logical expression – available operators: ! == != && || – parentheses can be used to group sub-expressions test for not defined #if !Logging ... both must be true #if Logging && Debugging ... both must have same value, either true or false #if Logging == Debugging ... 11
- Controlling line number and file name • Control line and file reported by compiler with #line – #line number - change line – #line number "filename" - change line and filename – #line default - restore true line numbers and filenames class Test { static void Main() { report line numbers #line 1 counting from 1 ... override line and file #line 5 "Source.cs" ... restore accurate reporting #line default ... } } 12
- Diagnostic directives • Can generate compile time warnings and errors – #warning – #error #if FinalReview warning #warning Recent change: updated 07-Nov-03 by MAT #endif #if Logging && MaximizePerformance error #error Turn off logging to maximize performance #endif 13
- Regions • Create logical group with #region and #endregion – have no effect on meaning of code – can supply name for region – can be convenient for programmer – can be read by development tools class Stock { fields #region Private fields private string name; private double price; private int shares; #endregion constructors #region Constructors public Stock(string name, double price, int shares) { ... } #endregion ... } 14
- Summary • C# compiler offers preprocessing as first stage of translation – can conditionally compile code – can control line numbers and file names reported by compiler – can emit warnings and errors – can define logical regions of source code 15
CÓ THỂ BẠN MUỐN DOWNLOAD
-
Tài liệu về lập trình web JSP
118 p | 3371 | 1222
-
Hướng dẫn học lập trình PHP &MySQL
56 p | 906 | 362
-
Ngôn ngữ PHP
34 p | 665 | 281
-
Căn bản về JSP
118 p | 403 | 179
-
Giới thiệu PHP
142 p | 468 | 155
-
Bài giảng về PHP
142 p | 428 | 92
-
Lập trình PHP - Bài 1: Giới thiệu, Cấu hình và cài đặt PHP
39 p | 217 | 84
-
Giới thiệu về PHP - AJAX
101 p | 182 | 66
-
Giải pháp thiết kế web động với PHP - p 3
10 p | 178 | 60
-
Thao tác CSDL với PHP
19 p | 171 | 56
-
C# and .NET Framework Lassion 3
17 p | 153 | 29
-
Hệ thống nhúng - Chương 1
15 p | 142 | 26
-
LẬP TRÌNH C nâng cao -BÀI 13 - RTTI, EXTERN VÀ PREPROCESSOR DIRECTIVE part 1
6 p | 222 | 26
-
PHP power programming
0 p | 116 | 26
-
LẬP TRÌNH C nâng cao -BÀI 13 - RTTI, EXTERN VÀ PREPROCESSOR DIRECTIVE part 2
5 p | 128 | 23
-
Truyền nhận dữ liệu qua môi trường web
0 p | 90 | 6
-
Web engineering: Lecture 19, 20 - Majid Mumtaz
19 p | 53 | 4
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn