Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
overflow.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <assert.h>
10#include <limits.h>
11#include <stdbool.h>
12#include <stddef.h>
13
21static inline bool sadd_overflow(int a, int b, int *res) {
22 assert(res != NULL);
23
24 // delegate to hardware optimized implementations where possible
25#if defined(__clang__) && \
26 (__clang_major__ > 3 || \
27 (__clang_major__ == 3 && __clang_minor__ > 7)) // Clang ≥ 3.8
28 return __builtin_sadd_overflow(a, b, res);
29#elif defined(__GNUC__) && __GNUC__ > 4 // GCC ≥ 5
30 return __builtin_sadd_overflow(a, b, res);
31#endif
32
33 if (a > 0 && INT_MAX - a < b) {
34 return true;
35 }
36 if (a < 0 && INT_MIN - a > b) {
37 return true;
38 }
39
40 *res = a + b;
41 return false;
42}
node NULL
Definition grammar.y:149
static bool sadd_overflow(int a, int b, int *res)
Definition overflow.h:21