\ at the End of the Line

This page was translated by a robot.

If a backslash occurs at the very end of a line without another whitespace \, the preprocessor will remove the end of the line and append the next line directly to the current one. This is used in particular for macro definitions, which by definition are only allowed to span one line, but are often too confusing to display in a single line.










a = (50, 60, 70)
#include <stdio.h>
#define SET(a, x, y, z) \
  a[0] = x;\
  a[1] = y;\
  a[2] = z

int main(){
  int a[3];
  SET(a, 50, 60, 70);
  printf("a = (%d, %d, %d)", a[0], a[1], a[2]);
  return 0;
}

Details

A backslash at the end of a line is not limited to macros alone. The preprocessor rigorously converts all occurrences throughout the code.

The use of the backslash at the end of the line should be used very carefully. It is known that a forgotten backslash or a backslash too many took up to several days of debugging. Although some compilers issue warnings such as backslash and newline separated by space if whitespace is accidentally added, there is no guarantee that these warnings will be given for every compiler. Very nasty errors can occur if a backslash is specified at the end of the file. Here, too, some compilers have built in a warning such as backslash-newline at end of file .