Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Wrong Warning #6165

Open
YoSTEALTH opened this issue Apr 26, 2024 · 2 comments
Open

[BUG] Wrong Warning #6165

YoSTEALTH opened this issue Apr 26, 2024 · 2 comments

Comments

@YoSTEALTH
Copy link
Contributor

YoSTEALTH commented Apr 26, 2024

Describe the bug

Both i and len are unsigned

Code to reproduce the behaviour:

cdef:
    unsigned int i
    __u16        len

if i < len-1:

warning: comparison of integer expressions of different signedness: ‘unsigned intandint’ [-Wsign-compare]
22194 |         __pyx_t_1 = (__pyx_cur_scope->__pyx_v_i < (__pyx_cur_scope->__pyx_v_self->__pyx_base.len - 1));
@da-woods
Copy link
Contributor

da-woods commented Apr 26, 2024

I think this is just C rules (described in https://en.cppreference.com/w/c/language/conversion).

If the signed type can represent all values of the unsigned type, then the operand with the unsigned type is implicitly converted to the signed type.

I assume __u16 is a 16-bit unsigned int. The 1 is a signed int (either 32 or 64 bit depending on the platform) so I think that rule will apply and len - 1 will also be a signed int.


Not completely sure though because I haven't read and understood all of that page. But I'm fairly sure this is mostly C and not Cython

@YoSTEALTH
Copy link
Contributor Author

I can avoid the error by setting i to be __u16 as well. I just figure you guys should know about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants