offset of a data member

Joined
Jan 24, 2008
Messages
4
Reaction score
0
Hi,

The below macro is defined in stddef.h standard header file.
#define offsetof(s,m) (size_t)&(((s *)0)->m)

This gives offset of member data 'm' in structure 's'

Ex:
struct example {
int a;
int b;
};

printf("%d", offsetof(example, b) ) displays 4 (In win32).

Please explain the behavior of above statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top