By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,497 Members | 2,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,497 IT Pros & Developers. It's quick & easy.

about address...

P: n/a
s88
Hi all:
I saw a code slice
<code>
&(((structure *)0)->m)
</code>
Looks like to identified the address of the element in the structure.
Could U explain that the meanning of the 0???

Thanx!!

Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
s88 wrote:
Hi all:
I saw a code slice
<code>
&(((structure *)0)->m)


Looks close to an implementation of offsetof macro. For further
details look at Jack Klein's excellent post here:
<http://groups.google.co.in/group/com....c/browse_frm/

thread/53b5e085cd53d9d9/dd6a40ce090ec975?q=offsetof&rnum=5#dd6a40ce090ec97 5>

Nov 15 '05 #2

P: n/a
s88 a écrit :
I saw a code slice
<code>
&(((structure *)0)->m)
</code>
Looks like to identified the address of the element in the structure.
Could U explain that the meanning of the 0???


This is a complicated way of writing

<code>
#include <stddef.h>

<...> offsetof(structure, m);

</code>

Do you really need to know about the gory details ?
--
A+

Emmanuel Delahaye
Nov 15 '05 #3

P: n/a

"s88" <da*****@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi all:
I saw a code slice
<code>
&(((structure *)0)->m)
</code>
Looks like to identified the address of the element in the structure.
Could U explain that the meanning of the 0???


Zero is being cast to a 'structure *' - it'd interesting to see structure,
and what 'm' is.
Nov 15 '05 #4

P: n/a
Does this idiom portable?
I means compile ok and run correctly on every platform and compiler.

"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote
:43***********************@nan-newsreader-06.noos.net...
s88 a ¨¦crit :
I saw a code slice
<code>
&(((structure *)0)->m)
</code>
Looks like to identified the address of the element in the structure.
Could U explain that the meanning of the 0???


This is a complicated way of writing

<code>
#include <stddef.h>

<...> offsetof(structure, m);

</code>

Do you really need to know about the gory details ?
--
A+

Emmanuel Delahaye

Nov 15 '05 #5

P: n/a
Mockey Chen a écrit :

[Please don't top-post. Fixed]
#include <stddef.h>

<...> offsetof(structure, m);
Is this idiom portable?
I means compile ok and run correctly on every platform and compiler.


Yes it has belonged to the C-language since 1989.

--
A+

Emmanuel Delahaye
Nov 15 '05 #6

P: n/a
"Mockey Chen" <mo*********@google.com> writes:
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote
:43***********************@nan-newsreader-06.noos.net...
s88 a ¨¦crit :
I saw a code slice
<code>
&(((structure *)0)->m)
</code>
Looks like to identified the address of the element in the structure.
Could U explain that the meanning of the 0???


This is a complicated way of writing

<code>
#include <stddef.h>

<...> offsetof(structure, m);

</code>

Does this idiom portable?
I means compile ok and run correctly on every platform and compiler.


Every conforming C implementation supports the offsetof() macro.

The code slice above is not portable. It's one possible
implementation of offsetof().

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.