offsetof - C stddef.h

C examples for stddef.h:offsetof

Type

macro

From

<cstddef>

Prototype

offsetof (type,member)

Description

returns the offset value in bytes of member member in the data structure or union type type.

Parameters

Parameter Description
type A type in which member is a valid member designator.
member A member of type.

Return value

A value of type size_t with the offset value of member in type.

Demo Code


#include <stdio.h>
#include <stddef.h>

struct foo {/*from w  ww . ja v a2  s  .c  o m*/
  char a;
  char b[10];
  char d[10];
  
  int i[1000];
  char c;
};

int main ()
{
  printf ("offsetof(struct foo,a) is %d\n",(int)offsetof(struct foo,a));
  printf ("offsetof(struct foo,b) is %d\n",(int)offsetof(struct foo,b));
  printf ("offsetof(struct foo,c) is %d\n",(int)offsetof(struct foo,c));

  return 0;
}

Related Tutorials