https://github.com/nodef/extra-swap.cxx
Macros to swap variables in C.
https://github.com/nodef/extra-swap.cxx
c cpp extra function macro merferry swap variable
Last synced: 6 months ago
JSON representation
Macros to swap variables in C.
- Host: GitHub
- URL: https://github.com/nodef/extra-swap.cxx
- Owner: nodef
- License: mit
- Created: 2017-10-16T20:26:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-04-10T20:00:18.000Z (10 months ago)
- Last Synced: 2025-04-10T21:19:04.466Z (10 months ago)
- Topics: c, cpp, extra, function, macro, merferry, swap, variable
- Language: C
- Homepage: https://cppf.github.io/extra-swap/
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Macros to swap variables in C.
> Download: [header file](https://raw.githubusercontent.com/cppf/extra-swap/master/main.h).
### default
```c
// Swap variables (xor).
ESWAP(vara, varb)
```
```c
// swap a, b
ESWAP(a, b);
printf("%x %x", a, b);
```
### var
```c
// Swap variables using third variable.
ESWAP_VAR(varx, vary, type)
```
```c
// define integers a, b
int a = 0x1122;
int b = 0x3344;
printf("%x %x", a, b);
// swap a, b
ESWAP_VAR(a, b, int);
printf("%x %x", a, b);
```
### buf
```c
// Swap variables using temporary buffer.
ESWAP_BUF(varx, vary)
```
```c
// swap a, b
ESWAP_BUF(a, b);
printf("%x %x", a, b);
```
### addsub
```c
// Swap variables using addition and subtraction.
ESWAP_ADDSUB(varx, vary)
```
```c
// swap a, b
ESWAP_ADDSUB(a, b);
printf("%x %x", a, b);
```
### xor
```c
// Swap variables using XOR.
ESWAP_XOR(varx, vary)
```
```c
// swap a, b
ESWAP_XOR(a, b);
printf("%x %x", a, b);
```
### bitsxor
```c
// Swap individual bits using XOR.
ESWAP_BITSXOR(varx, vary, bits)
```
```c
// swap higher 8 bits of a, b
ESWAP_BITSXOR(a, b, 0xFF00);
printf("%x %x", a, b);
```
### bits
```c
// Swap individual bits.
ESWAP_BITS(varx, vary, bits)
```
```c
// swap higher 8 bits of a, b
ESWAP_BITS(a, b, 0xFF00);
printf("%x %x", a, b);
```
[](https://cppf.github.io)
