Add an explanation for the swap macro.

This commit is contained in:
Enrico Fraccaroli (Galfurian)
2024-02-29 11:07:55 -05:00
parent d213276817
commit 7b6076b612
+7
View File
@@ -72,6 +72,13 @@ typedef unsigned int pgprot_t;
/// Counts the number of elements of an array.
#define count_of(x) ((sizeof(x) / sizeof((x)[0])) / ((size_t)(!(sizeof(x) % sizeof((x)[0])))))
/// @brief Swaps two values.
/// @details
/// do { ... } while (0) allows to place multistatement operations, for
/// instance, inside the following if stantement:
/// if (condition)
/// swap(var1, var2)
/// which otherwise would be wrong.
#define swap(a, b) \
do { \
typeof(a) temp = (a); \