C
C copied to clipboard
fix(build): Address various compiler warnings (ULL, const-correctness, Wformat)
Description of Change
Summary
This Pull Request addresses several compiler warnings found when compiling the repository with strict compiler flags (e.g., Clang 17.0.0 on macOS, which uses -Wall). These changes ensure better code quality, portability, and adherence to modern C standards without altering the functionality of the algorithms.
Specific Warnings Fixed
- Implicit Unsigned Literals (
-Wimplicitly-unsigned-literal):- Fixed by adding the
ULLsuffix to large constants indecimal_to_any_base.candhash_djb2.c.
- Fixed by adding the
- Double/Float Mismatch (
-Wabsolute-value):- Changed
fabsfto the double-precision functionfabsingeometry/vectors_3d.cbecause the variablealphais of typedouble.
- Changed
- Const-Correctness (
-Wincompatible-pointer-types-discards-qualifiers):- Applied an explicit cast
(const int **)in themainfunction ofmodified_binary_search.cto match the function signature, resolving the const-discarding warning.
- Applied an explicit cast
- Format Mismatch (
-Wformat):- Corrected the format specifier for
scanfincollatz.cto%lluto correctly read into auint64_t. - Corrected the
printfformat specifier inshell_sort2.cfrom%.4g(double) to%.4lu(unsigned long) for printingclock_tdifferences.
- Corrected the format specifier for
- Misc:
- Simplified array iteration initialization in
prime_factoriziation.c(C99 style initialization inside theforloop).
- Simplified array iteration initialization in
Thank you for reviewing!
Checklist
- [x] Added description of change
- [x] PR title follows semantic commit guidelines
- [x] Search previous suggestions before making a new one, as yours may be a duplicate.
- [x] I acknowledge that all my contributions will be made under the project's license.
Notes: