From: N N Ashok <nalkunda@cse.msu.edu>
To: "David S. Miller" <davem@redhat.com>
Cc: netdev@oss.sgi.com, linux-net@vger.kernel.org
Subject: Re: Casting (struct rtable*) to (struct dst_entry*)
Date: Thu, 20 Mar 2003 01:02:38 -0500 [thread overview]
Message-ID: <200303200102.38813.nalkunda@cse.msu.edu> (raw)
In-Reply-To: <20030319.213352.50358237.davem@redhat.com>
On Thursday 20 March 2003 00:33, David S. Miller wrote:
> From: N N Ashok <nalkunda@cse.msu.edu>
> Date: Thu, 20 Mar 2003 00:27:41 -0500
>
> I did see that. But however, I could not understand how "struct rtable"
> can be casted to "struct dst_entry" and then back again, all the while
> accessing fields of both structures.
>
> You miss the point that they are the same structure. It is allocated
> the size of "struct rtable" but it may be casted back and forth
> between rtable and dst_entry as desired.
>
> void foo(void)
> {
> struct rtable rt;
> struct dst_entry *dst;
>
> rt->u.dst.bar = 1;
>
> dst = (struct dst_entry *) &rt;
> ASSERT(dst->bar == 1);
>
> dst = &rt->u.dst;
> ASSERT(dst->bar == 1);
> }
I think I finally understand the whole setup. Please correct if I'm wrong.
"struct rtable" has its first field "u" which is a union of "dst_entry" and
"struct rtable *". Thus when we cast rtable to dst_entry, we are accessing
the rtable.u.dst_entry itself and not any other part of rtable.
Since originally the data was allocated the size of "rtable", when we cast
"dst_entry" to "struct rtable" we can access all the fields of "struct
table".
Thanks a lot for the clarification.
Ashok
prev parent reply other threads:[~2003-03-20 6:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-20 4:55 Casting (struct rtable*) to (struct dst_entry*) N N Ashok
2003-03-20 4:59 ` David S. Miller
2003-03-20 5:27 ` N N Ashok
2003-03-20 5:33 ` David S. Miller
2003-03-20 6:02 ` N N Ashok [this message]
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=200303200102.38813.nalkunda@cse.msu.edu \
--to=nalkunda@cse.msu.edu \
--cc=davem@redhat.com \
--cc=linux-net@vger.kernel.org \
--cc=netdev@oss.sgi.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;
as well as URLs for NNTP newsgroup(s).