Mastering the use of backslash continuation in C + + programming _c language

Source: Internet
Author: User

1 used in the macro definition:

#define CV_ARE_SIZES_EQ (MAT1, mat2) \
  ((mat1)->rows = = (MAT2)->rows && (mat1)->cols = = (MAT2)-> Cols

2 used in printf, sometimes the statement in printf is too long, need to be split, then use the backslash;
3) with "//" can only annotate the current line of statements, you want to comment out the next line, you can add a backslash at the end of the line.
In addition, the backslash has the meaning of the escape character in addition to the effect of the Force line wrapping. For example, "\ n" means line breaks, "t" "\b", and so on, at which point the backslash represents escape, and the symbol behind the backslash is executed.
However, to take a backslash, you need to precede the backslash with a backslash before you can properly represent it. For example, I want to read the F:\OpenCV2.0\vs2008\videos\videos1.avi in the program, I can not directly to this expression, but should be preceded by each backslash with a backslash, expressed as: f:\\opencv2.0\\vs2008\\ Videos\\videos1.avi, so that you can correctly read the file you want.
To sum up, the current personal understanding of the backslash effect is two kinds:
1 is an escape character, the action to be performed is the character immediately following it.
2 Force wrap with the ENTER key combination. In the place of the stronger line to enter a backslash and then return, the system will automatically compile the line below the backslash and the previous line to explain to a statement.

Line continuation character
after normal lines of code are the same (VC is automatically judged continuation of the line), but in the macro definition is particularly useful, because the macro definition must be completed in one line:

 #define SOMEFUN (x, a, B) if (x) X=a+b;else x=a-b;

This line of definitions is no problem, but this code is not easy to understand, later maintenance trouble, if written:

#define SOMEFUN (x, A, B)
 if (x)
  x = a + b;
else
  x = a-b;

This is a good understanding, but the compiler will make an error because it thinks that #define SOMEFUN (x, A, b) is a complete line, if (x) and subsequent statements have nothing to do with #define SOMEFUN (x, A, b).
That's when we have to use the same wording:

 #define SOMEFUN (x, a, b) \
if (x) \
x = a + b;\
else\
x = a-b;

Note: The last line does not add line characters. VC preprocessor will be automatically before compiling the \ and line break, so that neither affect reading, and not affect the logic, happy

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.