Skip to content

Commit c0853fd

Browse files
committed
4.6 Line continuation added
1 parent 4da6c8e commit c0853fd

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// CPP-Notes
3+
//
4+
// Created by Akshay Raj Gollahalli on 23/05/16.
5+
// Copyright © 2016 Akshay Raj Gollahalli. All rights reserved.
6+
//
7+
8+
#include <cstdio>
9+
using namespace std;
10+
11+
#define LOOPER(i) do \
12+
{ \
13+
printf("%d\n",i++); \
14+
} while (i < 3);
15+
16+
17+
int main(int argc, char ** argv) {
18+
19+
int a = 0;
20+
21+
LOOPER(a);
22+
23+
return 0;
24+
}
25+

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ C++ Notes
3535
- [4.3 Conditions in preprocessor](#43-conditions-in-preprocessor)
3636
- [4.4 Macro expansion](#44-macro-expansion)
3737
- [4.5 Problems with Macro's](#45-problems-with-macros)
38+
- [4.6 Line continuation](#46-line-continuation)
3839

3940
<!-- /TOC -->
4041

@@ -852,3 +853,16 @@ int main(int argc, char const *argv[]) {
852853
See [4_5_Macro_Problems.cpp](https://github.com/akshaybabloo/CPP-Notes/tree/master/4_Preprocessors/4_5_Macro_Problems.cpp)
853854
854855
You should always be careful when using parameterised macros. See [4_5_Macro_Problems.cpp](https://github.com/akshaybabloo/CPP-Notes/tree/master/4_Preprocessors/4_5_Macro_Problems.cpp) for more details.
856+
857+
### 4.6 Line continuation
858+
859+
See [4_6_Line_Continuation.cpp](https://github.com/akshaybabloo/CPP-Notes/tree/master/4_Preprocessors/4_6_Line_Continuation.cpp)
860+
861+
If you want to use complex macros you can use `line continuation` by add `\` at the end of the each line. For example:
862+
863+
```cpp
864+
#define LOOPER(i) do \
865+
{ \
866+
printf("%d\n",i++); \
867+
} while (i < 3);
868+
```

0 commit comments

Comments
 (0)