Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of such definition "#define __arch_swab32 __arch_swab32"? [duplicate]

Tags:

c

linux

In /usr/include/asm/swab.h I found following code:

static __inline__  __u32 __arch_swab32(__u32 val)
{
    __asm__("bswapl %0" : "=r" (val) : "0" (val));
    return val;
}
#define __arch_swab32 __arch_swab32

What is the meaning of the last line, defining a name as itself?

like image 755
Marek Niepieklo Avatar asked Aug 24 '17 09:08

Marek Niepieklo


1 Answers

This is called self-referentitial macro:

One common, useful use of self-reference is to create a macro which expands to itself. If you write

 #define EPERM EPERM

then the macro EPERM expands to EPERM. Effectively, it is left alone by the preprocessor whenever it's used in running text. You can tell that it's a macro with #ifdef. You might do this if you want to define numeric constants with an enum, but have #ifdef be true for each constant.

like image 143
haccks Avatar answered Oct 18 '22 13:10

haccks