offsetof

De RAD Studio
Aller à : navigation, rechercher

Remonter à stddef.h - Index


Header File

stddef.h

Category

Memory Routines

Prototype

size_t offsetof(struct_type, struct_member);

Description

Gets the byte offset to a structure member.

offsetof is available only as a macro. The argument struct_type is a struct type. struct_member is any element of the struct that can be accessed through the member selection operators or pointers.

If struct_member is a bit field, the result is undefined.

See also sizeof for more information on memory allocation and alignment of structures.

Return Value

offsetof returns the number of bytes from the start of the structure to the start of the named structure member.

Example

#include <stddef.h>
struct fill_struct
{
  int _f1, _f2, _f3;
  char* _str;
};

int _tmain(int argc, _TCHAR* argv[])
{
  printf("The _str member of fill_struct starts at offset %d", offsetof(fill_struct, _str));
  return 0;
}


Portability

POSIX Win32 ANSI C ANSI C++

+

+

+