[Numpy-discussion] char with native integer signedness

Robert Kern robert.kern at gmail.com
Thu Oct 31 12:31:48 EDT 2013


On Thu, Oct 31, 2013 at 4:19 PM, Geoffrey Irving <irving at naml.us> wrote:
>
> 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".

Fair enough. numpy doesn't distinguish between these cases as it only uses
plain 'char' for 'S' arrays, which don't really care about the numerical
value assigned the bits. It explicitly uses 'signed char' elsewhere, so
this platform setting isn't relevant to it. Consequently, numpy also
doesn't expose this platform setting. I think I stand by my recommendation.

--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131031/5ccf31e4/attachment.html>


More information about the NumPy-Discussion mailing list