![](images/graphics/blank.gif)
Preprocessor
lượt xem 1
download
![](https://tailieu.vn/static/b2013az/templates/version1/default/images/down16x21.png)
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
![](images/graphics/blank.gif)
CÓ THỂ BẠN MUỐN DOWNLOAD
-
Cấu trúc của 1 chương trình C++
66 p |
327 |
142
-
Giới thiệu về PHP - AJAX
101 p |
184 |
66
-
Giải pháp thiết kế web động với PHP - p 3
10 p |
182 |
60
-
Thao tác CSDL với PHP
19 p |
171 |
56
-
Bài Giảng Lập Trình Web -Chương 6: Lập trình Web với PHP
20 p |
142 |
44
-
C# and .NET Framework Lassion 3
17 p |
155 |
29
-
Hệ thống nhúng - Chương 1
15 p |
144 |
27
-
C# and .NET FrameworkBài 3: Lập trình nâng cao trong C#Đoàn Quang Minh minhdqtt@gmail.com
17 p |
96 |
6
-
Truyền nhận dữ liệu qua môi trường web
0 p |
91 |
6
-
Cài đặt PHP
7 p |
59 |
5
-
Bài giảng Ngôn ngữ C#: Chương 3 - Trần Văn Tèo
21 p |
88 |
4
-
Web engineering: Lecture 19, 20 - Majid Mumtaz
19 p |
56 |
4
![](images/icons/closefanbox.gif)
![](images/icons/closefanbox.gif)
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
![](https://tailieu.vn/static/b2013az/templates/version1/default/js/fancybox2/source/ajax_loader.gif)