On this page
  1. offsetof
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

offsetof

Prev: NULL | Up: stddef.h | Next: max_align_t
Rel: stddef.h, stdint, stdbool & limits Guide
Ref: cppreference — offsetof
Tags: #public #prog #c #stdlib #stddef #tier/standard


Include

#include <stddef.h>

Signature & Overview

size_t offsetof(type, member);

Compile-time byte offset of member from the start of struct type.

Notes & Pitfalls

Example

#include <assert.h>
#include <stddef.h>

struct Node { int id; double weight; };
int main(void) { assert(offsetof(struct Node, weight) >= sizeof(int)); }

Linked from

Related notes