com php-src: word on bit shifting: compat/PECL_PORTING
| From: | Anatol Belski | Date: | Tue, 28 Jan 2014 13:17:36 +0000 |
| Subject: | com php-src: word on bit shifting: compat/PECL_PORTING | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-75824@lists.php.net to get a copy of this message | ||
Commit: 90bce9f1e817ed95b9951ebd5da6319170c6e486
Author: Anatol Belski <ab@php.net> Tue, 28 Jan 2014 14:17:36 +0100
Parents: 82857031f015e1cf9dcbd9c48e0dfd4388a82ecc
Branches: str_size_and_int64
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=90bce9f1e817ed95b9951ebd5da6319170c6e486
Log:
word on bit shifting
Changed paths:
M compat/PECL_PORTING
Diff:
diff --git a/compat/PECL_PORTING b/compat/PECL_PORTING
index 1b3a916..872208e 100644
--- a/compat/PECL_PORTING
+++ b/compat/PECL_PORTING
@@ -23,6 +23,7 @@ III. Pitfalls
ii. zend_parse_parameters()
iii. Pointer difference
iv. RETURN_STRINGL, RETVAL_STRINGL
+ v. Bitwise operations
========================================
@@ -261,3 +262,24 @@ III. Pitfalls
While it's theoretically possible to use any other datatype with those macros, the
explicit attention should be paid that the values arn't negative.
+ v. Bitwise operations
+
+ Especialy some bitshift operations might bring unexpected results when mixing 32 and
+ 64 bit variables or constants. For example this snippet works different on 32 and
+ 64 bit platforms
+
+ php_int_t var = 1 << 31;
+
+ While a 32 bit variable can hold bits from 0 to 31, a 64 bit variable can hold bits
+ from 0 to 63. So with the snippet above the result the max negative value of 32 bit
+ integer. To have it working correct way, an explicit cast
+
+ php_int_t var = (php_int_t)1 << 31;
+
+ or the special macros in case of a constant
+
+ php_int_t var = Z_I(1) << 31;
+
+ can be used.
+
+