Skip to content

Commit

Permalink
Simplify swap() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 15, 2024
1 parent 9287a3d commit 2ff9811
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion c/src/include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#endif

#ifndef swap
#define swap(x, y, T) do { T SWAP = x; x = y; y = SWAP; } while (0)
#define swap(x, y) do { typeof(x) SWAP = x; x = y; y = SWAP; } while (0)
#endif

#if !(CL_COMPILER || TCC_COMPILER)
Expand Down
2 changes: 1 addition & 1 deletion c/src/p0025.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unsigned long long p0025() {
BCD_int a = BCD_one, b = BCD_one;
while (b.decimal_digits < 1000) {
iadd_bcd(&a, b);
swap(a, b, BCD_int);
swap(a, b);
answer++;
}
free_BCD_int(a);
Expand Down
6 changes: 5 additions & 1 deletion docs/src/c/lib/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ View source code :source:`c/src/include/macros.h`
.. c:macro:: max(a, b)
min(a, b)
If these were not already defined, this header makes them
If these were not already defined, this header makes them.
.. c:macro:: swap(x, y)
Swap the names of two variables of the same type.
.. c:macro:: likely(x)
unlikely(x)
Expand Down

0 comments on commit 2ff9811

Please sign in to comment.