Is the right-shift operator in Objective C on OSX/iOS an arithmetic or logical right shift?
I can’t find any references that specify whether the right-shift is arithmetic or logical, or if it varies depending on the data type (signed/unsigned) and/or architecture (x86/PPC/x64/ARM).
“Programming in Objective-C 2.0” states that this is effectively undefined, but that conflicts with information I’ve seen elsewhere that compilers attempt to “do the right thing” based on signed-ness of types.
I did a quick experiment in the iOS simulator, with the following fragment:
Which yielded the result:
This would seem to indicate that the shift is arithmetic, not logical, because the sign of the answer is preserved.