what is the use of #ifndefs
From: Raul Piper <hidden>
Date: 2015-07-21 05:05:48
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. #ifndef avoids this error .By placing it at the top all the declaration is visited just once =>How?Since suppose _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 #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 declaration error. On Tue, Jul 21, 2015 at 7:54 AM, Navy [off-list ref] wrote:
On Mon, Jul 20, 2015 at 12:03:07PM +0200, Ahmed Soliman wrote:quoted
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/kernelnewbiesThe whole structure seems to #ifndef ... #define ... . . . #endif _______________________________________________ Kernelnewbies mailing list Kernelnewbies at kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150721/78f31450/attachment-0001.html