summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2001-11-27 16:18:43 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2001-11-27 16:18:43 (GMT)
commit05264c88788f9bd9b04a58673ded246904210235 (patch)
tree33f87c572ce8078ed20a4622fec8f25a8c909f59 /src
parent6336d12b0383b7adcf29a91cf3dbbe4ceaff6d42 (diff)
downloadhdf5-05264c88788f9bd9b04a58673ded246904210235.zip
hdf5-05264c88788f9bd9b04a58673ded246904210235.tar.gz
hdf5-05264c88788f9bd9b04a58673ded246904210235.tar.bz2
[svn-r4642] Purpose:
Code cleanup Description: Added macro to check for overflows when assigning a value to a variable which requires a cast down in size or precision. Platforms tested: FreeBSD 4.4 (hawkwind)
Diffstat (limited to 'src')
-rw-r--r--src/H5private.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/H5private.h b/src/H5private.h
index e832987..dc15faa 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -445,6 +445,22 @@ MS doesn't recognize it yet (as of April 2001)
#endif /* NDEBUG */
/*
+ * A macro for detecting over/under-flow when assigning between types
+ */
+#ifndef NDEBUG
+#define H5_ASSIGN_OVERFLOW(var,expr,vartype,casttype) \
+{ \
+ vartype _tmp_overflow=(vartype)(expr); \
+ casttype _tmp_overflow2=(casttype)(_tmp_overflow); \
+ assert((casttype)_tmp_overflow==_tmp_overflow2); \
+ (var)=_tmp_overflow2; \
+}
+#else /* NDEBUG */
+#define H5_ASSIGN_OVERFLOW(var,expr,vartype,casttype) \
+ (var)=(casttype)(expr);
+#endif /* NDEBUG */
+
+/*
* Data types and functions for timing certain parts of the library.
*/
typedef struct {