what is the use of #ifndefs
Navy
navych at 126.com
Tue Jul 21 03:01:05 EDT 2015
On Tue, Jul 21, 2015 at 11:04:15AM +0530, Amit Pandey wrote:
> Hi Ahmed,
>
> See the comments inline
> #ifndef _LINUX_LIST_H // If not defined _LINUX_LIST_H macro
> #define _LINUX_LIST_H // then define this macro
> #include "linuxlist.h" // and include linuxlist.h header file
> #endif // end of #ifndef
>
> Now say in another file if u r not sure whether you have already included
> the "linuxlist.h" then you will again repeat above lines of code, assuming
> you have included it then certainly _LINUX_LIST_H macro has already been
> defined, so compiler will not include this file again. See comments below
>
> #ifndef _LINUX_LIST_H // Since macro _LINUX_LIST_H has already defined
> #define _LINUX_LIST_H // compiler will ignore this line
> #include "linuxlist.h" // compiler will ignore this line, too.
> Hence no multiple inclusion of same header file
> #endif
>
> Please let me know whether I was clear with the explanation.
>
> Thanks,
> Amit
>
> On Mon, Jul 20, 2015 at 3:33 PM, Ahmed Soliman <ahmedsoliman0x666 at gmail.com>
> wrote:
>
> > currently I started reading through the linux kernel and I started
> > reading liunx/include/linux/list.h> I understood some of the functions
> > but still I dont know what does these lines of code do
> > #ifndef _LINUX_LIST_H
> > #define _LINUX_LIST_H
> > which exist at the very beginning of the file
> > I also noticed that there is many similar ifndefs in almost any .h
> > file in the kernel
> > note that I understand wnat does ifndef do bu I dont understand what
> > goal is it supposed to achieve at the beginning of the headerfile
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Your explanation seems to be wrong.
The code below should in "linuxlist.h" ,other than in other files which include "linuxlist.h".
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
...
#endif
More information about the Kernelnewbies
mailing list