Program-C language details 15 (preprocessing command details # error, operator # And #, _ FILE _, _ LINE __)

Source: Internet
Author: User

Program-C language details 15 (preprocessing command details # error, operator # And #, _ FILE _, _ LINE __)
Main Content: preprocessing command details # error, operator # And #, _ FILE _, _ LINE __

# Include
 
  
/* Contains this header file, instead of linking all its functions to the Program * // * # Operator */# define MK_ID (n) I # n/* Indicates connecting two marks */int MK_ID (1), MK_ID (2), MK_ID (3);/* after preprocessing, it becomes int i1, i2, i3; * // * defines multiple types ##_ max functions. The return type and parameter type of the function are determined by define. * For example, GENERIC_MAX (int) is converted into int int_max (int x, int y) {return} return x> y? X: y; */# define GENERIC_MAX (type) \ type ##_ max (type x, type y) \ {\ return x> y? X: y; \}/* parentheses must be added if the macro definition contains parameters, as follows: */# define THREE_PI (3*3.1415) # define TEST (x) (x) * 10)/* # error usage. error indicates a serious error, most compilers immediately stop compiling */# if INT_MAX> 100000 # error int type is too small # endif/* # line command to change the row numbering method for the program, usually the numbers are 1, 2, 3 ,.... * // * # The operator converts a macro parameter to a string literal. */# define PRINT_INT (x) printf (# x "= % d \ n", x) /* The result is PRINT_INT (I/j) => printf ("I/j" "= % d \ n", I/j) => output I/j = 5 * // * # occupies a single row. It is a so-called empty command and does not work, some program ape is used to give the interval between Conditional compilation modules */# if INT_MAX> 1000 # error int # endif/* Conditional compilation */# define DEBUG/* No need for debugging A value */# if defined (DEBUG) # endifint main (int argc, char * argv []) {int I = 10, j = 2; PRINT_INT (I/j ); printf ("Compiled on % s at % d \ n" ,__ FILE __,__ LINE _);/* _ FILE _ indicates the current FILE, __line _ indicates the current LINE, which is used well during debugging, especially when the embedded linux driver */printf ("% s | % s \ n" ,__ DATE __, __time _);/* also has _ DATE ,__ TIME _ TIME */printf ("% d \ n" ,__ STDC __); /* _ STDC _ check whether the compiler results in Standard C. If yes, 1 */return 0 is returned ;}
 

Output:


Related Article

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.