From: navych@126.com (Navy)
To: kernelnewbies@lists.kernelnewbies.org
Subject: what is the use of #ifndefs
Date: Tue, 21 Jul 2015 15:01:05 +0800 [thread overview]
Message-ID: <20150721063737.GA4726@debian> (raw)
In-Reply-To: <CAODrRZF+y2oKqbW0TQyFzE1DnTEDQNxm0aemTwJTFFQx7oCbKg@mail.gmail.com>
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@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
next prev parent reply other threads:[~2015-07-21 7:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-20 10:03 what is the use of #ifndefs Ahmed Soliman
2015-07-20 15:55 ` leo kirotawa
2015-07-20 16:03 ` Stephan Müller
2015-07-20 16:11 ` Greg Freemyer
2015-07-20 17:00 ` anish singh
2015-07-21 2:24 ` Navy
2015-07-21 5:05 ` Raul Piper
2015-07-21 5:34 ` Amit Pandey
2015-07-21 7:01 ` Navy [this message]
2015-07-21 8:33 ` Bernd Petrovitsch
2015-07-21 19:44 ` Aruna Hewapathirane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150721063737.GA4726@debian \
--to=navych@126.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.