Re: [Cython] All DEF constants are now unsigned?

2015-09-06 Thread Jeroen Demeyer

On 2015-09-05 17:09, Stefan Behnel wrote:

It now appends the 'U' suffix only to literals that are used in an unsigned
context (e.g. assignment to unsigned variable), and additionally appends
L/LL suffixes for integers that might exceed the int/long limits.


Why not just keep it simple, append no suffixes and let the C/C++ 
compiler deal with it? No heuristics needed.


More concretely, I would handle this as follows:
* do not use any L or U suffix
* write all DEF constants as hexadecimal in the source code

This way, the C/C++ compiler will determine the integral type. It will 
use the first type in the following list which can represent the number:

- int
- unsigned int
- long
- unsigned long
- long long
- unsigned long long

The reason for the *hexadecimal* constants is that the unsigned types 
are not tried for decimal constants.

___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] All DEF constants are now unsigned?

2015-09-06 Thread Stefan Behnel
Jeroen Demeyer schrieb am 06.09.2015 um 10:54:
> On 2015-09-05 17:09, Stefan Behnel wrote:
>> It now appends the 'U' suffix only to literals that are used in an unsigned
>> context (e.g. assignment to unsigned variable), and additionally appends
>> L/LL suffixes for integers that might exceed the int/long limits.
> 
> Why not just keep it simple, append no suffixes and let the C/C++ compiler
> deal with it? No heuristics needed.
> 
> More concretely, I would handle this as follows:
> * do not use any L or U suffix
> * write all DEF constants as hexadecimal in the source code
> 
> This way, the C/C++ compiler will determine the integral type.

I previously tried that with decimal literals and got warnings in gcc.
Hadn't tried hex literals.


> It will use
> the first type in the following list which can represent the number:
> - int
> - unsigned int
> - long
> - unsigned long
> - long long
> - unsigned long long
> 
> The reason for the *hexadecimal* constants is that the unsigned types are
> not tried for decimal constants.

That's interesting to know (you were quoting 6.4.4 of the C standard
apparently). C - what a language full of wonders.

https://github.com/cython/cython/commit/37f6b07978d3ca1b41aae4d1dd747ee63e3b9265

Thanks!

Stefan

___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] All DEF constants are now unsigned?

2015-09-06 Thread Jeroen Demeyer

Thanks, I just tested Sage with latest master and all worked fine!
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] All DEF constants are now unsigned?

2015-09-06 Thread Stefan Behnel
Jeroen Demeyer schrieb am 06.09.2015 um 19:54:
> Thanks, I just tested Sage with latest master and all worked fine!

Thanks for testing.

Stefan

___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel