C++ convertion char int ARM

  arm, c++

I have this very simple C++ code :

#include <iostream>
int main() {
    std::cout << (int)(char)(int)char(-2);
    return 0;
}

I am executing it on different setups :

  • Ubuntu 20.04 x64 (g++) -> Output : -2
  • Windows 10 x64 MSVC 2017 -> Output : -2
  • MacOS x64 Clang -> Output -2
  • Ubuntu Armv8 (g++) / EC2 Instance -> Output : 254

I want to obtain -2 all the time, and I don’t understand this difference in behavior.

Does anyone have any idea?

Source: Windows Questions C++

LEAVE A COMMENT