Keil Logo

offsetof

Summary
#include <stddef.h>

int offsetof (
  structure,      /* structure to use */
  member);        /* member to get offset for */
Description

The offsetof macro calculates the offset of the member structure element from the beginning of the structure. The structure argument must specify the name of a structure. The member argument must specify the name of a member of the structure.

Return Value

The offsetof macro returns the offset, in bytes, of the member element from the beginning of struct structure.

Example
#include <stddef.h>

struct index_st
  {
  unsigned char type;
  unsigned long num;
  unsigned ing len;
  };

typedef struct index_st index_t;

void main (void) {
  int x, y;

  x = offsetof (struct index_st, len);  /* x = 5 */
  y = offsetof (index_t, num);          /* y = 1 */
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.