1 / 8

C Preprocessor

C Preprocessor. Overview Preprocessor Directives Conditional Compilation Predefined Symbolic Constants. Overview. Six phases to execute C: Edit Preprocess Compile Link Load Execute. C Preprocessor. All preprocessor directives begin with # Possible actions Inclusion of other files

nyx
Download Presentation

C Preprocessor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Preprocessor • Overview • Preprocessor Directives • Conditional Compilation • Predefined Symbolic Constants

  2. Overview • Six phases to execute C: • Edit • Preprocess • Compile • Link • Load • Execute

  3. C Preprocessor • All preprocessor directives begin with # • Possible actions • Inclusion of other files • Definition of symbolic constants & macros • Conditional compilation of program code • Conditional compilation of preprocessor directives

  4. Preprocessor Directives • #include preprocessor directive • #include <filename> • For standard library header files • Location based on system • #include "filename" • For programmer-defined header files • Function, structure, typedef definitions & global variables • Located in the same folder as the file being compiled

  5. Preprocessor Directives • #define for symbolic constants • #define identifier text • Creates symbolic constants • The “identifier” is replaced by “text” in the program • Example #define PI 3.14 area = PI * radius * radius; • Replaced by “area = 3.14 * radius * radius” by preprocessor before compilation

  6. Preprocessor Directives • #define for macros • #define macro-identifier text • Can have arguments • The macro is “expanded” in the program • Example #define AREA(x) ( (PI) * (x) * (x)) circle_area = AREA(5); • Expanded to “circle_area = ((3.14)*(5)*(5))” by preprocessor before compilation

  7. Conditional Compilation • Controls the execution of preprocessor directives & compilation of code • Define NULL, if it hasn’t been defined yet #if !defined(NULL) #define NULL 0 #endif • Use to comment out code (for comments) #if 0 code prevented from compiling #endif

  8. Predefined Symbolic Constants #include <stdio.h> int main(){ printf("%d\n%s\n%s\n%s\n", __LINE__, __FILE__, __DATE__, __TIME__); } • Output: 3 example.c Oct 13 2003 19:27:57 • line #, file name, compiled date, compiled time • See example.c

More Related