API reference / Math
SDL_clamp
Macro, SDL3
Keeps a value between a minimum and a maximum. This is a macro.
Declaration
#include <SDL3/SDL.h>
#define SDL_clamp(x, a, b)Parameters
x | The value. |
a | The minimum. |
b | The maximum. |
Return value
The limited value.
Example
square.x = SDL_clamp(square.x, 0.0f, WINDOW_WIDTH - square.w);See this code run in Read the keyboard. Download the full program (.zip)
Notes
- A macro can use its arguments more than one time. So do not pass an expression such as
i++.
In SDL2
The name is the same.