LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Why use __KERNEL__ and __ASSEMBLY__ in the kernel source code? (http://www.linuxquestions.org/questions/linux-kernel-70/why-use-__kernel__-and-__assembly__-in-the-kernel-source-code-4175453477/)

dawei 03-10-2013 05:05 AM

Why use __KERNEL__ and __ASSEMBLY__ in the kernel source code?
 
Why use following macros in the kernel source code?

1)
#ifdef __KERNEL__

...code...

#endif /* __KERNEL__ */

2)
#ifdef __ASSEMBLY__

...code...

#endif /* __ASSEMBLY__ */

Mara 03-10-2013 11:28 AM

Those are for kernel headers. In some cases user space programs/libraries use the kernel headers. To make them run/compile/see only things they need, there is the __KERNEL__ macro. It is defined during the kernel compilation.

It is very similar with __ASSEMBLY__. Assembly source uses some kernel headers. Some things are not valid in assembly, however (like C functions...). The macro is defined for assembly code and allows to mark the part of the definitions that is needed in assembly.

In general, you do not have to use those if nobody complains. If it is needed, you will get notified.


All times are GMT -5. The time now is 08:08 PM.