<div dir="ltr">This is to avoid multiple declarations.In header file you declare the variables and function names and these have to be declared just once otherwise you will get multiple declaration error.<div>#ifndef avoids this error .By placing it at the top all the declaration is visited just once =>How?Since suppose <span style="font-size:12.7272720336914px">_LINUX_LIST_H is not defined and when you enter the file #ifndef (if not defined) will be true , hence it will go to next line and define it using </span><span style="font-size:12.7272720336914px"> </span><span style="font-size:12.7272720336914px">#define _LINUX_LIST_H .Now Since #defines(Macros) have global scopes across all the files, if suppose in some other files you have included this file (which defines above macros) , it will check first #ifndef _LINUX_LIST_H , but since it has already been defiend it will not enter the next line and you will be saved from multiple </span>declaration<span style="font-size:12.7272720336914px"> error.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 21, 2015 at 7:54 AM, Navy <span dir="ltr"><<a href="mailto:navych@126.com" target="_blank">navych@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jul 20, 2015 at 12:03:07PM +0200, Ahmed Soliman wrote:<br>
> currently I started reading through the linux kernel and I started<br>
> reading liunx/include/linux/list.h> I understood some of the functions<br>
> but still I dont know what does these lines of code do<br>
> #ifndef _LINUX_LIST_H<br>
> #define _LINUX_LIST_H<br>
> which exist at the very beginning of the file<br>
> I also noticed that there is many similar ifndefs in almost any .h<br>
> file in the kernel<br>
> note that I understand wnat does ifndef do bu I dont understand what<br>
> goal is it supposed to achieve at the beginning of the headerfile<br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br>
The whole structure seems to<br>
#ifndef ...<br>
#define ...<br>
.<br>
.<br>
.<br>
#endif<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br></div>