what is the use of #ifndefs

Greg Freemyer greg.freemyer at gmail.com
Mon Jul 20 12:11:00 EDT 2015


That's basic C syntax for 30 years both in and out of the kernel.

If you include the same header file multiple times you can get errors
about defining the same structures, constants, globals multiple times.

So the first time it is included you want the header file to actually
be included.

For all subsequent times you want it ignored by the compiler.

And that is exactly what

#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H

causes to happen.

Greg Freemyer

On Mon, Jul 20, 2015 at 6:03 AM, 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

More information about the Kernelnewbies mailing list