signed chars are not converted to str: is this intentional? #4235
-
I've been using Sample code would be something like this in C++: m.def("pass_signed_char", [](signed char c) { return c; }); And in Python: example.pass_char("h") # Will get 105 instead of "h" I read through the documentation and the tests in I wonder if this is by design or just an oversight? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We never designed any of the casters with the intent of using signed chars. You can always do a conversion of the return value to unsigned chars with a lambda or function wrapper. The fact that unsigned chars gets cast to anything at all is surprising, it seems they are implicitly convertible to int which is why they work at all: https://en.cppreference.com/w/cpp/language/implicit_conversion |
Beta Was this translation helpful? Give feedback.
We never designed any of the casters with the intent of using signed chars. You can always do a conversion of the return value to unsigned chars with a lambda or function wrapper. The fact that unsigned chars gets cast to anything at all is surprising, it seems they are implicitly convertible to int which is why they work at all: https://en.cppreference.com/w/cpp/language/implicit_conversion