-
Notifications
You must be signed in to change notification settings - Fork 436
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
Avoid calling Windows max() and min() macros #1053
Conversation
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Do we have any idea why this started to happen? I think that would be essential to decide what the proper fix is. |
I don't know why it started to happen, but I tried reverting ros/pluginlib#186 and the connected PRs (also reverting ros/class_loader#139) and the failures went away. Here's a job I ran with all of the changes reverted: https://ci.ros2.org/job/ci_windows/9917 |
Regardless of how it started happening, this seems like a good, defensive, patch to me. If users include rclcpp headers into their code that also happens to include |
If |
I would suggest to try added the following before this newly added include https://github.com/ros2/rcutils/blob/f368c0f5b9666663f6c8e99b159221b4282d632c/include/rcutils/shared_library.h#L29:
|
The parenthesis is still safer, because all someone has to do is this:
To break it again. |
Use parentheses instead. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
I'd recommend doing both, merging ros2/rcutils#229 and doing something to protect ourselves, I'd recommend this: // This "dummy" macro is used to break up uses of min and max to avoid
// the min/max macros that may be defined by windows.h from breaking things.
// See: ...issue or additional resources here
#define PREVENT_WINDOWS_MIN_MAX_MACRO // could be shorter, I was being explicit
// ...
return (y > 0) && (x > (std::numeric_limits<T>::max PREVENT_WINDOWS_MIN_MAX_MACRO () - y));
// ...
Duration
Duration::max PREVENT_WINDOWS_MIN_MAX_MACRO ()
{
return Duration(std::numeric_limits<int32_t>::max PREVENT_WINDOWS_MIN_MAX_MACRO (), 999999999);
} This approach was suggested here: |
@wjwwood Why use a macro instead of parentheses? |
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Sadly, uncrustify doesn't like the parentheses (8dc3d6a). |
Because if I'm reading the code and see: return Duration((std::numeric_limits<int32_t>::max)(), 999999999); I think "that's weird, is that a mistake?" You could have a comment on each one, as you do in some places here, but if I see: return Duration(std::numeric_limits<int32_t>::max PREVENT_WINDOWS_MIN_MAX_MACRO (), 999999999); I think "What the heck is But it's completely subjective. |
I think #1054 is a better alternative, leaving code more readable. |
Signed-off-by: Esteve Fernandez <esteve.fernandez@tier4.jp>
Previously Windows CI was failing:

With this change: