LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 03-10-2013, 04:05 AM   #1
dawei
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
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__ */
 
Old 03-10-2013, 10:28 AM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,535

Rep: Reputation: 148Reputation: 148
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.
 
  


Reply

Tags
kernel, macro


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to attach a kernel module with kernel source code Gourab Das Linux - Kernel 2 02-04-2010 07:19 AM
How to access 2.6 kernel macros defined under __KERNEL__ someshwar Linux - Kernel 2 10-31-2006 11:36 PM
kernel source code ashley_31 Linux - General 10 05-23-2006 04:47 PM
Want 2.6.9-5 kernel source code bishalpoudyal Conectiva 1 04-13-2006 11:23 AM
kernel source code nabil_boussetta Linux - Software 7 02-13-2004 06:57 AM


All times are GMT -5. The time now is 03:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration