Description
GLib offers a set of macros for doing additions and multiplications
of unsigned integers, with checks for overflows.
The helpers all have three arguments. A pointer to the destination
is always the first argument and the operands to the operation are
the other two.
Following standard GLib convention, the helpers return TRUE in case
of success (ie: no overflow).
The helpers may be macros, normal functions or inlines. They may be
implemented with inline assembly or compiler intrinsics where
available.
Functions
g_uint_checked_add()
#define g_uint_checked_add(dest, a, b)
Performs a checked addition of a
and b
, storing the result in
dest
.
If the operation is successful, TRUE is returned. If the operation
overflows then the state of dest
is undefined and FALSE is
returned.
Returns
TRUE if there was no overflow
Since: 2.48
g_uint_checked_mul()
#define g_uint_checked_mul(dest, a, b)
Performs a checked multiplication of a
and b
, storing the result in
dest
.
If the operation is successful, TRUE is returned. If the operation
overflows then the state of dest
is undefined and FALSE is
returned.
Returns
TRUE if there was no overflow
Since: 2.48
g_uint64_checked_add()
#define g_uint64_checked_add(dest, a, b)
Performs a checked addition of a
and b
, storing the result in
dest
.
If the operation is successful, TRUE is returned. If the operation
overflows then the state of dest
is undefined and FALSE is
returned.
Returns
TRUE if there was no overflow
Since: 2.48
g_uint64_checked_mul()
#define g_uint64_checked_mul(dest, a, b)
Performs a checked multiplication of a
and b
, storing the result in
dest
.
If the operation is successful, TRUE is returned. If the operation
overflows then the state of dest
is undefined and FALSE is
returned.
Returns
TRUE if there was no overflow
Since: 2.48
g_size_checked_add()
#define g_size_checked_add(dest, a, b)
Performs a checked addition of a
and b
, storing the result in
dest
.
If the operation is successful, TRUE is returned. If the operation
overflows then the state of dest
is undefined and FALSE is
returned.
Returns
TRUE if there was no overflow
Since: 2.48
g_size_checked_mul()
#define g_size_checked_mul(dest, a, b)
Performs a checked multiplication of a
and b
, storing the result in
dest
.
If the operation is successful, TRUE is returned. If the operation
overflows then the state of dest
is undefined and FALSE is
returned.
Returns
TRUE if there was no overflow
Since: 2.48