On this page
SIZE_MAX
Prev: PRIu64 | Up: stdint.h | Next: stddef.h
Rel: stdint.h, stdint, stdbool & limits Guide
Ref: cppreference — SIZE_MAX
Tags: #public #prog #c #stdlib #stdint #tier/standard
Include
#include <stdint.h>
Signature & Overview
#define SIZE_MAX /* max value of size_t */
Maximum representable value of size_t, used for overflow checks before multiplication.
Notes & Pitfalls
- Always check for multiplication overflow before
malloc(n * sizeof(T)):if (n > SIZE_MAX / sizeof(T))prevents heap buffer overflows.
Example
#include <assert.h>
#include <stdint.h>
int main(void) {
size_t n = 1000;
assert(n <= SIZE_MAX / sizeof(int));
}
Linked from
Related notes
- tuts/c/stdlib/stdint/PRIu64 Linked here; links to this page; shared tags: #c, #prog, #stdint, #stdlib, #tier
- tuts/c/stdlib/stdint Linked here; links to this page; shared tags: #c, #prog, #stdint, #stdlib
- tuts/c/stdlib/stddef Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdint_stdbool_and_limits Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdint/int32_t shared tags: #c, #prog, #stdint, #stdlib, #tier
- tuts/c/stdlib/stdint/int64_t shared tags: #c, #prog, #stdint, #stdlib, #tier
- tuts/c/stdlib/stdint/uint32_t shared tags: #c, #prog, #stdint, #stdlib, #tier
- tuts/c/stdlib/stdint/uint64_t shared tags: #c, #prog, #stdint, #stdlib, #tier
- tuts/c/stdlib/stdint/uint8_t shared tags: #c, #prog, #stdint, #stdlib, #tier
- tuts/c/stdlib/stdint/uintptr_t shared tags: #c, #prog, #stdint, #stdlib, #tier