Home > Back-end > About the C language macro definition
About the C language macro definition
Time:04-20
Sample: (not an error) # define div (a, b) a % b;
Sample 2: (not an error) # define div (a, b) a % b
Sample 3: (not an error) T=# define change (a, b) a, a=b, b=t;
Sample 4: (not an error) T=# define change (a, b) a, a=b, b=t
The sample 5: (error) # define s (a, b, c) ((a + b + c)/2); # define area (a, b, c, S) SQRT (S * (S - a) * (S - b) * (S - c));
The sample 6: (not an error) # define s (a, b, c) ((a + b + c)/2) # define area (a, b, c, S) SQRT (S * (S - a) * (S - b) * (S - c))
Want to ask about why the sample in the CB five complains, how to determine parameters of macro definition behind add do not add "; "?
CodePudding user response:
You are using is the Angle of the semicolon!
CodePudding user response:
What mistake? In the code and how to use s, area? These is the key, can't say that only the macro definition will be an error or no error, the key is how to use the macro definition is equivalent substitution, in the code to see whether conform to the rules of grammar ~
CodePudding user response:
VC compiler options/EP/P (projects, properties, configuration properties, C/C + +, the preprocessor, pretreatment to the file: is that the preprocessing cancel display line Numbers: is), recompile, view the corresponding after macro expansion. I file, GCC - E http://bbs.csdn.net/topics/391003898
CodePudding user response:
If s (a, b, c) directly involved in the operations in the code behind, do not add a semicolon, such as S (a, b, c) + 123.//s can't have a plus sign in the
Direct call, when it does not participate in the operation, it can be added, suggest not to add the S (a, b, c)