<s>
It	O
evaluates	O
to	O
the	O
offset	O
(	O
in	O
bytes	O
)	O
of	O
a	O
given	O
member	O
within	O
a	O
struct	B-Language
or	O
union	O
type	O
,	O
an	O
expression	O
of	O
type	O
.	O
</s>
<s>
The	O
offsetof( )	O
macro	O
takes	O
two	O
parameters	O
,	O
the	O
first	O
being	O
a	O
structure	O
name	O
,	O
and	O
the	O
second	O
being	O
the	O
name	O
of	O
a	O
member	O
within	O
the	O
structure	O
.	O
</s>
<s>
While	O
this	O
implementation	O
works	O
correctly	O
in	O
many	O
compilers	O
,	O
it	O
has	O
generated	O
some	O
debate	O
regarding	O
whether	O
this	O
is	O
undefined	B-Language
behavior	I-Language
according	O
to	O
the	O
C	O
standard	O
,	O
since	O
it	O
appears	O
to	O
involve	O
a	O
dereference	O
of	O
a	O
null	O
pointer	O
(	O
although	O
,	O
according	O
to	O
the	O
standard	O
,	O
section	O
6.6	O
Constant	O
Expressions	O
,	O
Paragraph	O
9	O
,	O
the	O
value	O
of	O
the	O
object	O
is	O
not	O
accessed	O
by	O
the	O
operation	O
)	O
.	O
</s>
<s>
Some	O
modern	O
compilers	O
(	O
such	O
as	O
GCC	B-Application
)	O
define	O
the	O
macro	O
using	O
a	O
special	O
form	O
(	O
as	O
a	O
language	O
extension	O
)	O
instead	O
,	O
e.g.	O
</s>
<s>
It	O
is	O
useful	O
when	O
implementing	O
generic	O
data	O
structures	O
in	O
C	O
.	O
For	O
example	O
,	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
uses	O
to	O
implement	O
,	O
which	O
allows	O
something	O
like	O
a	O
mixin	B-Language
type	O
to	O
find	O
the	O
structure	O
that	O
contains	O
it	O
:	O
</s>
<s>
The	O
linux	B-Operating_System
kernel	I-Operating_System
implementation	O
of	O
container_of	O
uses	O
a	O
GNU	B-Application
C	I-Application
extension	O
called	O
statement	O
expressions	O
.	O
</s>
<s>
This	O
implementation	O
would	O
also	O
serve	O
the	O
same	O
purpose	O
,	O
however	O
,	O
there	O
's	O
a	O
fundamental	O
omission	O
in	O
terms	O
of	O
the	O
original	O
linux	B-Operating_System
kernel	I-Operating_System
implementation	O
.	O
</s>
<s>
The	O
type	O
of	O
ptr	O
is	O
never	O
checked	O
against	O
the	O
type	O
of	O
the	O
member	O
,	O
this	O
is	O
something	O
that	O
the	O
linux	B-Operating_System
kernel	I-Operating_System
implementation	O
would	O
catch	O
.	O
</s>
<s>
Usage	O
of	O
offsetof	B-Language
is	O
limited	O
to	O
POD	B-Language
types	O
in	O
C++98	O
,	O
standard-layout	O
classes	O
in	O
C++11	B-Language
,	O
and	O
more	O
cases	O
are	O
conditionally-supported	O
in	O
C++17	B-Language
,	O
otherwise	O
it	O
has	O
an	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
The	O
following	O
program	O
will	O
generate	O
several	O
warnings	O
and	O
print	O
obviously	O
suspicious	O
results	O
when	O
compiled	O
with	O
gcc	B-Application
4.7.3	O
on	O
an	O
amd64	O
architecture	O
:	O
</s>
