aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-01-29 17:35:55 -0500
committerMustafa Quraish <[email protected]>2022-01-29 17:35:55 -0500
commit4b5f0a130f6c5220e25492c2377d77617e54eec1 (patch)
treeaf65006dbaf401c83aeaffa73aa94786e39833ab
parentAllow uninitialized variable declarations (diff)
downloadcup-4b5f0a130f6c5220e25492c2377d77617e54eec1.tar.xz
cup-4b5f0a130f6c5220e25492c2377d77617e54eec1.zip
Add i64{max,min} helper functions
-rw-r--r--cup/utils.c5
-rw-r--r--cup/utils.h3
2 files changed, 7 insertions, 1 deletions
diff --git a/cup/utils.c b/cup/utils.c
index 79d849e..2335981 100644
--- a/cup/utils.c
+++ b/cup/utils.c
@@ -24,4 +24,7 @@ void _die_location(char *file, int line, Location loc, const char *fmt, ...)
fprintf(stderr, "\n");
fprintf(stderr, "NOTE: Error occurred in %s:%d\n", file, line);
exit(1);
-} \ No newline at end of file
+}
+
+i64 i64max(i64 a, i64 b) { return a > b ? a : b; }
+i64 i64min(i64 a, i64 b) { return a < b ? a : b; } \ No newline at end of file
diff --git a/cup/utils.h b/cup/utils.h
index ae81f8d..dfc018c 100644
--- a/cup/utils.h
+++ b/cup/utils.h
@@ -6,4 +6,7 @@
void die(const char *fmt, ...);
void _die_location(char *file, int line, Location loc, const char *fmt, ...);
+i64 i64max(i64 a, i64 b);
+i64 i64min(i64 a, i64 b);
+
#define die_location(loc, ...) _die_location(__FILE__, __LINE__, loc, __VA_ARGS__) \ No newline at end of file