Macros in C are divided into two types: object-like macro and function-like macro ).
Predefined macros:
1. The behavior of the predefined macro is specified by the compiler.
2. The front and back parallel bars are generally pre-defined.
2. _ COUNTER _ is a predefined macro. This value will be counted from 0 during compilation, and 1 will be added each time it is called.
3. _ FILE _ returns the absolute path of the current FILE.
4. _ LINE _ returns the number of rows in the file when the macro is expanded.
5. _ func _ indicates the function name of the scope where the macro is located.
6. _ VA_ARGS _ indicates all the remaining parameters in... in macro definition.
7. Output rect, size, and point macros:
- #define NSLogRect(rect) NSLog(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
- #define NSLogSize(size) NSLog(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
- #define NSLogPoint(point) NSLog(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
8. Use ({...}) format. This type of statement can be similar to many scripting languages. After sequential execution, the value of the last expression is returned. For example, after the following code is executed, the value of a is 3, and B and c only exist in the code domain limited by braces:
- int a = ({
- int b = 1;
- int c = 2;
- b + c;
- });
- // => a is 3
9. # Is a special symbol in a macro. It indicates connecting two parameters. 10. # the function of a single well number is to convert it into a C string by adding "" to the two ends after replacement.