Go Back   UseSrv Message Forum > Linux > Linux Development > Linux System Development
 

 
Thread Tools Display Modes
  #1  
Old 06-25-2008
kernel.lover
Guest
 
Posts: n/a
Default Linux kernel header files

Hello,
Why linux kernel header files start with defining
constant variables? EX. header file list.h
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
also header file lock.h
#ifndef _LINUX_LOCKS_H
#define _LINUX_LOCKS_H
Why they are defined and where its require by kernel?
  #2  
Old 06-25-2008
David Schwartz
Guest
 
Posts: n/a
Default Re: Linux kernel header files


"kernel.lover" <cranium.2003@gmail.com> wrote in message
news:1d55641b.0503021851.378e6f2@posting.google.co m...
> Hello,
> Why linux kernel header files start with defining
> constant variables? EX. header file list.h
> #ifndef _LINUX_LIST_H
> #define _LINUX_LIST_H
> also header file lock.h
> #ifndef _LINUX_LOCKS_H
> #define _LINUX_LOCKS_H
> Why they are defined and where its require by kernel?


They are defined to prevent errors if you include the header file twice.
Sometimes one header file will include another header file, and if not for
this, this could result in errors.

DS


  #3  
Old 06-25-2008
Erik de Castro Lopo
Guest
 
Posts: n/a
Default Re: Linux kernel header files

"kernel.lover" wrote:
>
> Hello,
> Why linux kernel header files start with defining
> constant variables? EX. header file list.h
> #ifndef _LINUX_LIST_H
> #define _LINUX_LIST_H
> also header file lock.h
> #ifndef _LINUX_LOCKS_H
> #define _LINUX_LOCKS_H
> Why they are defined and where its require by kernel?


They are called and include guard. See here:

http://c2.com/cgi/wiki?IncludeGuard

It is not required by the kernel. Its is however a useful C
and C++ program technique.

Erik

--
+-----------------------------------------------------------+
Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"I'm not proud .... We really haven't done everything we could
to protect our customers ... Our products just aren't engineered
for security." -- Brian Valentine, Senior Vice President of
Microsoft's Windows development team
  #4  
Old 06-25-2008
kernel.lover
Guest
 
Posts: n/a
Default Re: Linux kernel header files

> They are defined to prevent errors if you include the header file twice.
> Sometimes one header file will include another header file, and if not for
> this, this could result in errors.
>
> DS


Thanks for reply. I got it. But one thing i also want to know if
list.h and my1.h is included by my1.c where suppose my1.h already
included list.h then if in file i add header file in sequence like
#include <lish.h>
#include "my1.h"
then how the definition _LINUX_LIST_H can be resolved? Does
kernel stores all these defined variable in any files to resolve same
files not to be added avoiding multiple definitions?


Thread Tools
Display Modes

Forum Jump


All times are GMT. The time now is 01:21 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0