Re: what is the use of #ifndefs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Mon, Jul 20, 2015 at 3:03 AM, Ahmed Soliman <ahmedsoliman0x666@xxxxxxxxx> 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

It makes sure that the file doesn't get included twice.Suppose
you have a.c and a.h file and  you have #include "thisfile"(where
you have that #ifndef thing) in both a.c and a.h file then it will
be included only once. Because once .c or .h includes it then
that particular #define is already defined so next time it will
not execute when someone tries to include it again.

Hope that helps.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux