/***1. Macros are simply replaced when the compiler is compiling the source code, without any logical detection, that is, simple code copying. 2. When a macro is defined, the type of the parameter is not considered. 3. The use of a parameter macro causes a block of code with the same effect to have multiple copies in the destination file, which increases the size of the target file. 4. Parameter macros run faster than functions because they do not require a parameter stack/stack operation. 5. The parameter macro should be more careful when defining, extra parentheses. 6. The function only exists in one place in the target file, which saves the program space. 7. Function calls will involve the transfer of parameters, the stack/stack operation, the speed is relatively slow. 8. The parameter of the function has the problem of passing the value and passing the address (pointer), the parameter macro does not exist. */#include<cstdio>typedefstructpoint3d{floatx; floaty; floatZ;} Point3D;//function Mode//void Point3d_print (const point3d* PD)//{//printf ("%g,%g,%g", Pd->x, Pd->y, pd->z);//%g Select%e or%f printf ("%.2g", 0.0123) according to the specific values, and the ====> 0.012 effect is equivalent to the number of significant digits removed after 0//}//macro Way, for simple functions you can consider using macros, because faster#definePoint3d_print (PD) \printf ("%g,%g,%g", Pd->x, Pd->y, pd->z);intMain () {Point3D PD= {1.01f,1.0f,1.0f}; Point3D* p = &PD; Point3d_print (p);//This is not a direct use of &PD, you must define a pointer, such as p, this macro a bit of a pit barGetChar (); return 0;}
Macros and functions