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 _MAX warning in stepper.h #27272

Merged

Conversation

ellensp
Copy link
Contributor

@ellensp ellensp commented Jul 15, 2024

Description

#26881 added a _MAX comparision between and int and a unsigned int

resulting in a warning that gets repeated a number of times

Marlin\src\module\../inc/../core/macros.h: In instantiation of 'constexpr decltype ((lhs + rhs)) _MAX(L, R) [with L = int; R = unsigned int; decltype ((lhs + rhs)) = unsigned int]':
Marlin\src\module\stepper.h:302:13:   required from here
Marlin\src\module\../inc/../core/macros.h:395:20: warning: comparison of integer expressions of different signedness: 'const int' and 'const unsigned int' [-Wsign-compare]
  395 |         return lhs > rhs ? lhs : rhs;

The line that triggers this is in stepper.h

_MAX((STEPPER_TIMER_RATE) / HAL_TIMER_TYPE_MAX, 1U) // 32-bit shouldn't go below 1

since (STEPPER_TIMER_RATE) / HAL_TIMER_TYPE_MAX is never negative, tell the compiler this

diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h
index 2a171bebd0..c24953c24e 100644
--- a/Marlin/src/module/stepper.h
+++ b/Marlin/src/module/stepper.h
@@ -299,7 +299,7 @@ class Stepper {
     // and avoid the most unreasonably slow step rates.
     static constexpr uint32_t minimal_step_rate = (
       #ifdef CPU_32_BIT
-        _MAX((STEPPER_TIMER_RATE) / HAL_TIMER_TYPE_MAX, 1U) // 32-bit shouldn't go below 1
+        _MAX((uint32_t(STEPPER_TIMER_RATE) / HAL_TIMER_TYPE_MAX), 1U) // 32-bit shouldn't go below 1
       #else
         (F_CPU) / 500000U   // AVR shouldn't go below 32 (16MHz) or 40 (20MHz)
       #endif

This PR implements this

Requirements

Marlin with 26881

Benefits

Users don't panic over trivial warnings.

Configurations

https://github.com/MarlinFirmware/Configurations/tree/bugfix-2.1.x/config/examples/Creality/Ender-3%20V2/CrealityV422/CrealityUI

Related Issues

  • [BUG] Warning: comparison of integer expressions of different signedness: 'const int' and 'const unsigned int' #27271
  • @thinkyhead thinkyhead merged commit 5140726 into MarlinFirmware:bugfix-2.1.x Jul 15, 2024
    62 checks passed
    @ellensp ellensp deleted the fix-_MAX-warning-in-stepper.h branch July 15, 2024 19:52
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [BUG] Warning: comparison of integer expressions of different signedness: 'const int' and 'const unsigned int'
    2 participants