ds 0.10.0
A C library to safely yet efficiently work with UTF-8–encoded, growable dynamic strings.
usize.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef DS_USIZE_H
4#define DS_USIZE_H 1
5
6//! @file ds/usize.h
7//! @author Avinash Maddikonda (svasssakavi@gmail.com)
8//! @brief Declaration of the @ref ds_usize_t "usize" type, related constants
9//! and functions.
10//! @since 0.1.0
11//! @date 2023-07-24
12
13#include <stddef.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C"
18{
19#endif /* __cplusplus */
20
21 /// @brief The pointer-sized unsigned integer type.
22 ///
23 /// The size of this type, @ref DS_USIZE_BYTES "DS_USIZE_BYTES", is how many
24 /// bytes it takes to reference any location in memory. For example, on a 32
25 /// bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.
26 typedef size_t ds_usize_t;
27
28/// @brief The size of @ref ds_usize_t "usize" in bytes.
29///
30/// ### Examples
31///
32/// Basic usage:
33///
34/// ```c
35/// assert (DS_USIZE_BYTES == sizeof (size_t));
36/// ```
37#define DS_USIZE_BYTES ((ds_usize_t)sizeof (ds_usize_t))
38
39/// @brief The smallest value that can be represented by @ref ds_usize_t
40/// "usize".
41///
42/// ### Examples
43///
44/// Basic usage:
45///
46/// ```c
47/// assert (DS_USIZE_MIN == 0);
48/// ```
49#define DS_USIZE_MIN ((ds_usize_t)0)
50
51/// @brief The largest value that can be represented by @ref ds_usize_t "usize"
52/// (2<sup>64</sup> − 1 on 64-bit targets, 2<sup>32</sup> − 1 on 32-bit).
53///
54/// ### Examples
55///
56/// Basic usage:
57///
58/// ```c
59/// assert (DS_USIZE_MAX == SIZE_MAX);
60/// ```
61#define DS_USIZE_MAX ((ds_usize_t)SIZE_MAX)
62
63/// @brief @ref ds_usize_t "usize" notation. Can be used in `scanf` to parse
64/// and read @ref ds_usize_t "usize" values.
65///
66/// @warning It is strongly advised to use
67/// [`fgets`](https://en.cppreference.com/w/c/io/fgets "fgets -
68/// cppreference.com") instead of `scanf` to read input.
69///
70/// ### Examples
71///
72/// Basic usage:
73///
74/// ```c
75/// ds_usize_t x;
76/// scanf ("%" DS_SCN_USIZE, &x);
77/// ```
78#define DS_SCN_USIZE "zu"
79
80/// @brief @ref ds_usize_t "usize" notation. Can be used in `printf` to format
81/// and write @ref ds_usize_t "usize" values.
82///
83/// ### Examples
84///
85/// Basic usage:
86///
87/// ```c
88/// ds_usize_t const x = DS_USIZE_MAX;
89/// printf ("%" DS_PRI_USIZE, x);
90/// ```
91#define DS_PRI_USIZE "zu"
92
93#ifdef __cplusplus
94}
95#endif /* __cplusplus */
96
97#endif /* DS_USIZE_H */
size_t ds_usize_t
The pointer-sized unsigned integer type.
Definition: usize.h:26