Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:07:55+00:00 2026-05-30T01:07:55+00:00

#define offsetof(type, member) ((size_t)(&((type *)0)->member)) I am not understanding (&((type *)0)->member) what is this

  • 0
#define offsetof(type, member)  ((size_t)(&((type *)0)->member))

I am not understanding (&((type *)0)->member) what is this exactly telling me…..

here type may be a structure or something else??…

More specifically what is that 0 telling me here??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:07:56+00:00Added an answer on May 30, 2026 at 1:07 am

    I break it down like this:

    1. (type *)0 – casting 0 to a pointer to type “type“. i.e. imagine for a minute that there’s an object of type “type” at memory address 0.

    2. ->member – look into the object for the field called member.

    3. & – take the address of that.

    You could also write it like this:

    ((size_t)((&((type *)x)->member) - x))
    

    But we’re cheating and using 0 so that there’s no offset to take off at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Linux's stddef.h defines offsetof() as: #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) whereas the Wikipedia
Example from MSVC's implementation: #define offsetof(s,m) \ (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m)) // ^^^^^^^^^^^ As
In linux, container_of macro is enclosed in seemingly extra parentheses: #define container_of(ptr, type, member)
In ANSI C, offsetof is defined as below. #define offsetof(st, m) \ ((size_t) (
I found a method of computing the offset of struct. as follow: #define offsetOf(type
#define __HAVE_ARCH_STRCPY What's the meaning of __HAVE_ARCH ? I'm not a native speaker and
I define an enumerated type in MATLAB classdef(Enumeration) Color < Simulink.IntEnumType enumeration RED(0), GREEN(1),
#define cimg_use_jpeg 2 #ifndef cimg_use_jpeg //code goes here #endif I really don't understand...
#define LINK_ENTITY_TO_CLASS(mapClassName,DLLClassName) \ static CEntityFactory<DLLClassName> mapClassName( #mapClassName ); This is a macro from the
I cannot seem to implement offsetof for a structure in ctypes. I have seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.