summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-05-11 20:48:06 +0000
committerrubidium <rubidium@openttd.org>2010-05-11 20:48:06 +0000
commitbe504a6ef0f26b78216699d6995ccc8dee02a5c1 (patch)
tree97bb83daf3620edf7a128da731e3e43d450d359d /src/core
parent26bf9a13deea2da71142a6259ede951e08e75d01 (diff)
downloadopenttd-be504a6ef0f26b78216699d6995ccc8dee02a5c1.tar.xz
(svn r19788) -Codechange: make FOR_EACH_SET_BIT not change the value of the passed bit variable, i.e. allow expressions as parameter
Diffstat (limited to 'src/core')
-rw-r--r--src/core/bitmath_func.hpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp
index 85eaee6f9..a6b2ae446 100644
--- a/src/core/bitmath_func.hpp
+++ b/src/core/bitmath_func.hpp
@@ -310,16 +310,18 @@ static FORCEINLINE T ROR(const T x, const uint8 n)
* Do an operation for each set set bit in a value.
*
* This macros is used to do an operation for each set
- * bit in a variable. The first variable can be reused
- * in the operation due to it's the bit position counter.
- * The second variable will be cleared during the usage
+ * bit in a variable. The first parameter is a variable
+ * that is used as the bit position counter.
+ * The second parameter is an expression of the bits
+ * we need to iterate over. This expression will be
+ * evaluated once.
*
* @param i The position counter
* @param b The value which we check for set bits
*/
#define FOR_EACH_SET_BIT(i, b) \
- for (i = 0; b != 0; i++, b >>= 1) \
- if (b & 1)
+ for (uint __FESB_bits = (i = 0, b); __FESB_bits != 0; i++, __FESB_bits >>= 1) \
+ if (__FESB_bits & 1)
#if defined(__APPLE__)