[Numpy-discussion] char with native integer signedness
Geoffrey Irving
irving at naml.us
Thu Oct 31 12:19:41 EDT 2013
On Thu, Oct 31, 2013 at 2:08 AM, Robert Kern <robert.kern at gmail.com> wrote:
> On Thu, Oct 31, 2013 at 12:52 AM, Geoffrey Irving <irving at naml.us> wrote:
>>
>> Is there a standard way in numpy of getting a char with C-native
>> integer signedness? I.e.,
>>
>> boost::is_signed<char>::value ? numpy.byte : numpy.ubyte
>>
>> but without nonsensical mixing of languages?
>
> This is for interop with a C/C++ extension, right? Do this test in that
> extension's C/C++ code to expose the right dtype. As far as I know, this is
> not something determined by the hardware, but the compiler used. Since the
> compiler of numpy may be different from your extension, only your extension
> can do that test properly.
It's not determined by the hardware, but I believe it is standardized
by each platform's ABI even if it can be adjusted by the compiler.
>From the gcc man page:
-funsigned-char
Let the type "char" be unsigned, like "unsigned char".
Each kind of machine has a default for what "char" should
be. It is either like "unsigned char" by
default or like "signed char" by default.
Ideally, a portable program should always use "signed char"
or "unsigned char" when it depends on the
signedness of an object. But many programs have been
written to use plain "char" and expect it to be
signed, or expect it to be unsigned, depending on the
machines they were written for. This option, and
its inverse, let you make such a program work with the
opposite default.
The type "char" is always a distinct type from each of
"signed char" or "unsigned char", even though its
behavior is always just like one of those two.
Geoffrey
More information about the NumPy-Discussion
mailing list