[Cython] Use of long type for intermediate integral variables

David Vierra codewarrior0 at gmail.com
Fri Jul 3 02:26:26 CEST 2015


Very informative discussion. I see that Cython doesn't actually know the 
underlying types of typedefs because it doesn't parse any C headers. 
Cython doesn't even care about the exact length of the underlying type, 
just that it can order the types by rank to find which of two types is 
widest. When you write `ctypedef`, you're just telling Cython that two 
types are equivalent.

I second the opinion that the stdint.h typedefs in the standard library 
should have accurate definitions. This way `ctypedefs` that resolve to a 
stdint type will not be too wrong.

It might be safe just to change the ctypedefs for int64_t to `long long` 
- per the C99 standard, this type is *always* at least 64-bits long. (I 
don't know if all compilers adhere to this part of the spec and don't 
feel like getting a list of every compiler's opinion...but I know for 
sure it's 64 bits on MSVC, which doesn't claim to implement C99 nor even 
provide a stdint.h in the 2008 version.)

David Vierra
MCEdit, a Minecraft World Editor
http://www.mcedit.net
http://twitter.com/codewarrior0

On 7/2/2015 10:11 AM, Ian Henriksen wrote:
> On Thu, Jul 2, 2015 at 1:08 PM Robert McGibbon <rmcgibbo at gmail.com 
> <mailto:rmcgibbo at gmail.com>> wrote:
>
>     Right, okay. I think I understand.
>
>     -Robert
>
>     On Thu, Jul 2, 2015 at 12:58 AM, Stefan Behnel
>     <stefan_ml at behnel.de <mailto:stefan_ml at behnel.de>> wrote:
>
>         Robert McGibbon schrieb am 02.07.2015 um 09:49:
>         >> "libc.stdint.int64_t" is hand-wavingly declared as "long"
>         >
>         > There are some deeper issues in the rest of your message,
>         but as a
>         > preliminary matter, isn't this a clear error for linux-32
>         and windows?
>
>         No, it's not. That's just what Cython sees. The C compiler
>         then sees the
>         exact platform specific type. And as the vast amount of Cython
>         code out
>         there shows, it's usually not a problem in practice. Cython is
>         designed to
>         handle most of these "platform specific type" issues at C
>         compile time
>         rather than C code generation time. But as your example shows,
>         it can't
>         always hide the details entirely. And there can be bugs.
>
>         Stefan
>
>         _______________________________________________
>         cython-devel mailing list
>         cython-devel at python.org <mailto:cython-devel at python.org>
>         https://mail.python.org/mailman/listinfo/cython-devel
>
>
>     _______________________________________________
>     cython-devel mailing list
>     cython-devel at python.org <mailto:cython-devel at python.org>
>     https://mail.python.org/mailman/listinfo/cython-devel
>
>
> This is an interesting discussion. Thanks.
> For the particular case of int64_t, wouldn't it still be wise to
> make it a typedef of long long rather than just long so as to 
> consistently get the correct size on platforms where long
> is only 32 bits?
> Thanks!
> -Ian Henriksen
>
>
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> https://mail.python.org/mailman/listinfo/cython-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20150702/0803d9ee/attachment-0001.html>


More information about the cython-devel mailing list