Macros and functions and comparisons in C + +:
1, frequent use and perform simple calculations can use macros, and other more cumbersome, complex programs can be implemented with functions.
2, the macro definition is independent of the type, and the function needs to pay attention to the type of parameters.
3, the name of the macro definition is all uppercase, and the function name is the use of letters and "_" to name.
4, macro parameters have certain side effects, you need to note: "()" use, and the function does not exist these problems.
5. In C + +, macros are generally not used (macro functions--inline functions, solid---const, enum).
6. In C, macros cannot be debugged, and there is no type security check, but in C + +.
#include <stdio.h> #define M 9#define CAT (x, y) x# #Y # define printf (Format,value) printf ("The VALUE of" #VALUE ":" FORMAT "", VALUE), int main () {PRINTF ("%d\n", M);p rintf ("%d\n", CAT (123,321));p rintf ("File:%s\t line:%d\t date:%s\t Time :%s\n ", __file__,__line__,__date__,__time__); return 0;}
This article is from the "Flower Open Shore" blog, please be sure to keep this source http://zxtong.blog.51cto.com/10697148/1752737
Comparison of macros and functions (c + +)