Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does \ mean while calling a function in C?

I was looking some code, and saw that it used a \ to separate lines while calling a function, does this mean something? Or is it just to be more readable?

        function(\
        lets_say_this_a_long_attribute, \
        and_this_is_another_attribute_with_a_long_name_or_operations, \
        attribute);
like image 667
XuChen Avatar asked Jan 01 '23 04:01

XuChen


1 Answers

From the C Standard (5.1.1.2 Translation phases)

  1. Each instance of a backslash character () immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.

For example these physical lines

i\
n\
t\
 x;

form the logical line

int x;

Here is a demonstrative program.

#include <stdio.h>

int main(void) 
{
    i\
n\
t\
 x = 10;

    p\
r\
i\
n\
t\
f
    ( "%d\n", 
    x );

    return 0;
}

Its output is

10

This technique is used for writing macros like for example #define.

like image 118
Vlad from Moscow Avatar answered Jan 11 '23 18:01

Vlad from Moscow