|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
"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
|
|||
|
|||
|
"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
|
|||
|
|||
|
> 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 | |
|