diff --git a/src/stralloc.h b/src/stralloc.h
index 164546c42b30f0dfc830a4218f4745b5537dbf63..11032b95660a1ec968708e47a42fea609b706654 100644
--- a/src/stralloc.h
+++ b/src/stralloc.h
@@ -144,10 +144,17 @@ PMOD_EXPORT p_wchar2 index_shared_string(const struct pike_string *s, ptrdiff_t
 
 /* arithmetic left shift. compilers will understand this
  * and generate one arithmetic left shift. Left shifting
- * a negative integer is undefined and could be optimized
- * away by compilers.
+ * a negative integer is implementation defined and
+ * not all compilers do arithmetic left shifts.
  */
-#define SAL(a, b)	((a) < 0 ? -(-(a) << (b)) : (a) << (b))
+__attribute__((unused))
+static INLINE ptrdiff_t SAL(ptrdiff_t a, unsigned int b) {
+    if (a < 0) {
+        return -(-a << b);
+    } else {
+        return a << b;
+    }
+}
 
 #define EXTRACT_CHARP(PTR,SHIFT) INDEX_CHARP((PTR),0,(SHIFT))
 #define CHARP_ADD(PTR,X,SHIFT) (PTR)+=SAL(X,SHIFT)