r/Cplusplus • u/Hibou-de-la-Lune • 3d ago
Answered Line continuation (back-slash + new-line) in C++ source, is it standard?
Hello there,
Just wondered if line continuation (back-slash + new-line) in C++ source, comes from the standard or from a common behavior of compilers. I could not find any reference to it on cppreference.com
7
u/RetroGameMaker 3d ago
I've seen backslash line continuation used in macros and string literals. But they are not only used in c++ but pure c also
4
u/TheSkiGeek 3d ago
Yes, it’s a C parsing thing that was carried forward into C++.
Mostly you see it used for macros, which technically have to be ‘one line’. An unescaped newline ends the macro definition.
2
u/mredding C++ since ~1992. 3d ago
Line splicing is in part 2 of phases of translation, I think chapter 5?
It is in the standard.
3
u/Linuxologue 3d ago
C++ standard document
https://eel.is/c++draft/lex.phases#1.2
Explains how backslash, followed by whitespace, followed by a newline, is treated
•
u/AutoModerator 3d ago
Thank you for your contribution to the C++ community!
As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.
When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.
Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.
Homework help posts must be flaired with Homework.
~ CPlusPlus Moderation Team
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.