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

Fix warnings from backwards-loops #2899

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

ZedThree
Copy link
Contributor

Changes backward-loops over lists* from this pattern:

int i;
size_t length_of_list = /* ... */;
for(i=length_of_list-1;i>=0;i--) {
...

to this:

size_t length_of_list = /* ... */;
for(size_t i = length_of_list; i-->0;) {
...

This form enables using an unsigned type for the loop index, which usually fixes a couple of sign conversion warnings.


* or at least those that currently trigger sign-conversion warnings in the for statement or in the loop body

Enables using correct `size_t` type for loop counter, usually fixing
some conversion warnings
@WardF
Copy link
Member

WardF commented Apr 2, 2024

Interesting, and good catch, thanks! Looking at this now; I was out for the past week so there is a bit to catch up on.

@WardF WardF merged commit 0b9631f into Unidata:main Apr 2, 2024
103 checks passed
@ZedThree ZedThree deleted the silence-reverse-loop-warnings branch April 25, 2024 07:50
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

Successfully merging this pull request may close these issues.

2 participants