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

Prevent warning due to type-limits on arrsetlen(arr, 0) #1732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

josealvim
Copy link

Related to #1731.

As suggested by @nothings, cast array capacity and new capacity to ptrdiff_t in order to avoid 'always-false´ complaints that arise from -Wextra.

Why?

I tend to work on projects with pretty restrictive flags (-Wall -Wextra etc.), and I've introduced a dependency on stb_ds, as it is an excellent library that I use a lot. Unfortunately, arrsetlen(arr, 0) + -Wextra always produces an extraneous warning because the array capacity is unsigned, and thus the array-growth part of setlen is always-false.

Since the workaround is pretty trivial, I don't think it is a problem to satisfy stricter compilation options in this case.

Why not?

Theoretically this runs the risk of being a bad cast, since PTRDIFF_MAX < SIZE_MAX. Is there a realistic case where this would be a problem? I'm mostly referring to funky platforms I may not be aware of.


Thanks a lot, folks, it's a great library.

As suggested by @nothings, cast array capacity and new capacity to
`ptrdiff_t` in order to avoid 'always-false´ complaints that arise
from `-Wextra`.
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.

1 participant