From: Fawad Lateef <fawadlateef@gmail.com>
To: Mateusz Berezecki <mateuszb@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
kernel-mentors@selenic.com
Subject: Re: kernel list / container_of aka list_entry question
Date: Sun, 25 Dec 2005 22:24:42 +0500 [thread overview]
Message-ID: <1e62d1370512250924r4e3078d0ubb8986d52ac8aeb@mail.gmail.com> (raw)
In-Reply-To: <aec8d6fc0512250850m4f8d4bd6y3772638d620548cd@mail.gmail.com>
On 12/25/05, Mateusz Berezecki <mateuszb@gmail.com> wrote:
> I have two questions and I'll keep them short
>
> First one is about list_entry definition which is just a wrapper to
> container_of with exactly the same arguments (namely, ptr, type, member)
> whereas container_of is defined as follows
>
<snip>
> #define container_of(ptr, type, member) ({ \
> const typeof( ((type *)0)->member ) *__mptr = (ptr); \
> (type *)( (char *)__mptr - offsetof(type,member) );})
>
>
> My question is why is there a '0' inside a definition?
>
The Statement ----> const typeof( ((type *)0)->member) *__mptr =
(ptr); is basically declaring a constant pointer of the data-type
exactly same as the member data-type of the type (can be "struct foo"
let say) argument. For this by specifying ((type *)0)->member you
actually telling the compiler that at the address 0 my type (struct
foo) pointer is located and get me the member field of it and then my
typeof you are getting the typeof the member field. If you don't
specify (type *)0 then how you can tell the compiler to get the typeof
member field of the type (struct foo).
I hope you are will be able to get answer with my explanation.
> The second question is why the following code generates errors
> during compilation. list.h header file is included.
>
> struct atheros_priv *priv = ieee80211_priv(dev); /* line number 141 */
> struct list_head *iterator;
>
>
> list_for_each(iterator, &priv->rxbuf.list) {
> struct ath_buf *bf = list_entry(iterator, (struct ath_buf), list);
>
> /* ... some operations on *bf here ... */
> }
>
> and errors are as follows
>
> CC [M] /home/mb/atheros/transmit_receive.o
> /home/mb/atheros/transmit_receive.c: In function 'ath_startrecv':
> /home/mb/atheros/transmit_receive.c:141: error: syntax error before ')' token
> /home/mb/atheros/transmit_receive.c:141: error: '__mptr' undeclared
> (first use in this function)
> /home/mb/atheros/transmit_receive.c:141: error: (Each undeclared
> identifier is reported only once
> /home/mb/atheros/transmit_receive.c:141: error: for each function it
> appears in.)
> /home/mb/atheros/transmit_receive.c:141: error: syntax error before ';' token
> /home/mb/atheros/transmit_receive.c:141: error: syntax error before ')' token
> /home/mb/atheros/transmit_receive.c:141: error: syntax error before '(' token
> /home/mb/atheros/transmit_receive.c:141: error: 'list' undeclared
> (first use in this function)
> make[2]: *** [/home/mb/atheros/transmit_receive.o] Error 1
>
>
I just say that check your header files included, because I think the
.h file containing definition of struct ath_buf is not included and
the list_entry won't able to create __mptr pointer or so !
--
Fawad Lateef
next prev parent reply other threads:[~2005-12-25 17:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-25 16:50 Mateusz Berezecki
2005-12-25 17:24 ` Fawad Lateef [this message]
2005-12-25 18:10 ` Michael Buesch
2005-12-25 18:28 ` Mateusz Berezecki
2005-12-25 18:55 ` Fawad Lateef
2005-12-25 18:30 ` Mateusz Berezecki
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=1e62d1370512250924r4e3078d0ubb8986d52ac8aeb@mail.gmail.com \
--to=fawadlateef@gmail.com \
--cc=kernel-mentors@selenic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mateuszb@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®