On this page
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
- Compile-time byte offset of a struct member: Powers intrusive linked lists (
container_ofmacro) and binary serialization tables.
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
- tuts/c/stdlib/stddef/max_align_t Linked here; links to this page; shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/stddef/NULL Linked here; links to this page; shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/stddef Linked here; links to this page; shared tags: #c, #prog, #stddef, #stdlib
- tuts/c/stdlib/stdint_stdbool_and_limits Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stddef/ptrdiff_t shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/stddef/size_t shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier