Detailed explanation of pre-processing commands and pre-processing commands

Source: Internet
Author: User

Detailed explanation of pre-processing commands and pre-processing commands

As a C/C ++ programmer, we encounter various compilation commands when writing and viewing the C/C ++ Source Code. These commands are called preprocessing commands. Although the pre-processing command is not part of C/C +, it extends the design environment of the C program, the following C/C + training expert will show you how to use preprocessing programs and annotations to simplify the program development process and improve the readability of the program. All the pre-processing commands in the C language defined by ANSI start with the symbol #. For example, I often use the following: # define, # undef, # include, # if, # else, # elif, # endif, # ifdef, # ifndef, # error1. # define and # the general format of undef macro-defined commands is: # define [MacroName] [MacroValue], for example: # define ITHEIMA: The Dark Horse programmer in the source program changes it with the defined value every time he encounters ITHEIMA. L when using this macro, pay attention to the following points: n this statement does not have a semicolon. There can be any space between the identifier and string. When defining a macro, you can use a previously defined macro. N if the string is longer than one row, you can use a backslash '\' to continue the row at the end of the row. # Define LONG_STRING "good study, \ day up! "N. Generally, uppercase letters are required for defining macro identifiers. L use of preprocessing operators: n # -- this symbol indicates "stringized". In the macro definition, # converts the following parameters into a string # define ERROR_LOG (module) fprintf (stderr, "error:" # module "\ n") ERROR_LOG ("add"); convert to fprintf (stderr, "error:" add "\ n "); ERROR_LOG (devied = 0); convert to fprintf (stderr, "error: devied = 0 \ n"); n ##-- is a connection symbol that connects multiple strings together. Char * szStr = "broadcast podcast _ "; # defineITCAST (exp) cout <sz # exp <endl; ITCAST (Str) // cout <szStr <endl; // spell variable name l # undef-remove the macro name defined previously # undef [MacroName], for example: # undef ITHEIMA2. # include command # I nclude enables the compiler to embed another source file into the source file with # include. The source file to be read must be enclosed by double quotation marks or angle brackets. For example, the Code # include "stdio. h" or # include uses the C compiler to read and compile the subroutine used to process the disk file library. Embedding a file into a file in the # I nclude command is feasible. This method is called nested embedded files. The nested layers depend on the specific implementation. L if the explicit path name is part of the object identifier, search for the embedded object only in those subdirectories. For example: # include "../include/head. h" l if the file name is enclosed in double quotation marks, the current working directory is retrieved first. If no file is found, search all directories described in the command line. If no file is found, search for the standard directory defined during implementation. For example, include "head. h" l. If the file name is enclosed by Angle brackets, it is first retrieved in the directory of the compiled command line. If the file is not found, the standard directory is retrieved and the current working directory is not retrieved. Example: include

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.