Skip to content

Conversation

@german-one
Copy link
Contributor

Even with cryptic variable names we cannot fully avoid to shadow variables in user code. However, we absolutely can use different variable names in the API to avoid shadowing when macros are nested.

Even with cryptic variable names we cannot fully avoid to shadow variables in user code. However, we absolutely can use different variable names in the API to avoid shadowing when macros are nested.
@german-one
Copy link
Contributor Author

german-one commented Mar 24, 2025

Reviewing this PR might be easier with "Hide whitespaces" checked.
https://github.com/eteran/c-vector/pull/83/files?diff=unified&w=1

@eteran
Copy link
Owner

eteran commented Mar 25, 2025

I'll have to take a look. Looks like a lot of small changes so may take a little bit 👍.

@german-one
Copy link
Contributor Author

german-one commented Mar 25, 2025

I forgot to mention that this doesn't just address potential issues.
That's what I get when I compile the unit tests:
image
cv_sz__ declared in cvector_resize is shadowed in cvector_grow via cvector_reserve.

Admittedly, instead of thinking long and hard about under which circumstances further warnings of that kind could be triggered, I took the pragmatic approach and simply gave all variables a unique name.

[...] Looks like a lot of small changes [...]

Yes, really only renaming of variables declared in the macros. With whitespaces hidden it's easier to spot.

@eteran eteran merged commit 982843b into eteran:master Apr 9, 2025
5 checks passed
@eteran
Copy link
Owner

eteran commented Apr 9, 2025

Looks great, thanks!

@german-one german-one deleted the no_shadowing branch April 9, 2025 17:48
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