skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
h-stddef
This page is read only. You can view the source, but not change it.
# <stddef.h> **[<stddef.h>](https://en.cppreference.com/w/c/header/stddef)** provides fundamental types and macros: `size_t` (for sizes), `ptrdiff_t` (pointer differences), `wchar_t`, `NULL`, and `offsetof()`. Most headers include it transitively, but it's essential to include directly for portable code. Use `size_t` for array indices and loop counters, never `int`. ## Example This example queries structure member offsets and demonstrates `size_t` usage. ```c // compile: gcc -o stddefexample stddefexample.c // run: ./stddefexample // description: query struct member offsets and sizes #include <stddef.h> #include <stdio.h> struct packet { char type; int length; unsigned int checksum; }; int main() { printf("sizeof(packet) = %zu\n", sizeof(struct packet)); printf("offset(type) = %zu\n", offsetof(struct packet, type)); printf("offset(length) = %zu\n", offsetof(struct packet, length)); printf("offset(checksum) = %zu\n", offsetof(struct packet, checksum)); return 0; } ``` ## Common types and macros - `size_t`: unsigned type for sizes and indices - `ptrdiff_t`: signed type for pointer differences - `wchar_t`: wide character type - `NULL`: null pointer constant - `offsetof(type, member)`: byte offset of struct member
Page Tools
Show pagesource
Backlinks
Back to top