From 7b6076b612ca526ae40e62ae59a1d0df95cae5b2 Mon Sep 17 00:00:00 2001 From: "Enrico Fraccaroli (Galfurian)" Date: Thu, 29 Feb 2024 11:07:55 -0500 Subject: [PATCH] Add an explanation for the swap macro. --- libc/inc/stddef.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libc/inc/stddef.h b/libc/inc/stddef.h index 5e89e7a..6eb5b2f 100644 --- a/libc/inc/stddef.h +++ b/libc/inc/stddef.h @@ -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); \