0

I am reading through the source code from Linux 0.11 and I came about this block of code in unistd.h:

#define _syscall3(type,name,atype,a,btype,b,ctype,c) \
type name(atype a,btype b,ctype c) \
{ \
long __res; \
__asm__ volatile ("int $0x80" \
    : "=a" (__res) \
    : "0" (__NR_##name),"b" ((long)(a)),"c" ((long)(b)),"d" ((long)(c))); \
if (__res>=0) \
    return (type) __res; \
errno=-__res; \
return -1; \
}

What does the symbol \ mean at the end of each line?

code writer 3000
  • 329
  • 5
  • 19
  • 1
    it's a way to make macros more readable by splitting it up into multiple lines. The `\` character ignores the newline character for the macro, effectively merging all the lines into one long macro. – Blackgaurd Jun 22 '21 at 23:40

2 Answers2

1

OK, see that #define at the first line? it means we are talking about the "C PreProcessor"

So, it is basically defining an "alias" for something (in this case, for _syscall3(type,name,atype,a,btype,b,ctype,c)). It will replace every occurrence of the defined string, with its alias, anywhere it finds it in the source code. BEFORE the compiler begins to parse the code, do the compiler will read the long version.

Since the pre-processor in theory handles one line/command at the time, but humans are terrible reading LONG strings, we have the \ to 'concatenate' all those lines into a single line. Now we can actually read the code!

So, to answer your question: The \ means the line will continue below.

Octavio Galindo
  • 330
  • 2
  • 9
0

A macro ends with the end of the line. This would create realy long lines. To avoid this you can extend the line with .

#define add(a,b)\
((a)+(b))

is the same as

#define add(a,b) ((a)+(b))
NoNae
  • 332
  • 3
  • 10