Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Linux kernel #define a symbol as itself?

Tags:

c

linux-kernel

In the Linux kernel, there can be found a line of code that looks redundant to me:

#define __arch_swahb32 __arch_swahb32

What is the purpose of an idiom like this?

like image 720
IljaBek Avatar asked Dec 07 '16 12:12

IljaBek


People also ask

What type of kernel is Linux?

Linux is a monolithic kernel while OS X (XNU) and Windows 7 use hybrid kernels.

Is Linux a kernel or OS?

Linux, in its nature, is not an operating system; it's a Kernel. The Kernel is part of the operating system – And the most crucial. For it to be an OS, it is supplied with GNU software and other additions giving us the name GNU/Linux. Linus Torvalds made Linux open source in 1992, one year after it's creation.

Why Linux kernel is written in C?

The UNIX operating system's development started in 1969, and its code was rewritten in C in 1972. The C language was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code.


1 Answers

Consider the following code:

#ifdef foo
    foo();
#endif

If you want a snippet like the above to call function foo, you need to define foo. However, if you just

#define foo

then the function foo name will be replaced with an empty token, and the first snippet is preprocessed to just ();. If, however, you

#define foo foo

then the first snippet will preprocess to foo(); as it should.

like image 168
Nominal Animal Avatar answered Oct 16 '22 02:10

Nominal Animal