C icon indicating copy to clipboard operation
C copied to clipboard

fix(build): Address various compiler warnings (ULL, const-correctness, Wformat)

Open jesper-olsen opened this issue 1 month ago • 0 comments

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

  1. Implicit Unsigned Literals (-Wimplicitly-unsigned-literal):
    • Fixed by adding the ULL suffix to large constants in decimal_to_any_base.c and hash_djb2.c.
  2. Double/Float Mismatch (-Wabsolute-value):
    • Changed fabsf to the double-precision function fabs in geometry/vectors_3d.c because the variable alpha is of type double.
  3. Const-Correctness (-Wincompatible-pointer-types-discards-qualifiers):
    • Applied an explicit cast (const int **) in the main function of modified_binary_search.c to match the function signature, resolving the const-discarding warning.
  4. Format Mismatch (-Wformat):
    • Corrected the format specifier for scanf in collatz.c to %llu to correctly read into a uint64_t.
    • Corrected the printf format specifier in shell_sort2.c from %.4g (double) to %.4lu (unsigned long) for printing clock_t differences.
  5. Misc:
    • Simplified array iteration initialization in prime_factoriziation.c (C99 style initialization inside the for loop).

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:

jesper-olsen avatar Nov 18 '25 13:11 jesper-olsen