Fast swap for C
Macros | Functions
fswap.h File Reference

Go to the source code of this file.

Macros

#define __swap_fast(A, B)
 Main swap routine macro, not use other functions directly. More...
 

Functions

void __swap_ppp (void ***a, void ***b)
 Swap triple pointers types. More...
 
void __swap_pp (void **a, void **b)
 Swap double pointers types. More...
 
void __swap_p (void *a, void *b, size_t na, size_t nb)
 Swap all sized types. More...
 

Macro Definition Documentation

#define __swap_fast (   A,
 
)

Main swap routine macro, not use other functions directly.

In the macro, the type of object and its size are determined. Depending on this, the function and the swap (copy) mode are selected.

Parameters
Aany C types, equals B.
Bany C types, equals A.

Example: Variable A, B - any C types pointer.

int ia = 10, ib = 20, *pia = &ia, *pib = &ib;
printf("%d)\tInt* pia = %d, pib = %d\n", __LINE__, *pia, *pib);
__swap_fast(pia, pib);
printf("%d)\tInt* pia = %d, pib = %d\n", __LINE__, *pia, *pib);
int iaa[] = { 1, 2, 3, 4, 5 }, iba[] = { 6, 7, 8, 9, 0 };
__swap_fast(iaa, iba);
printf("%d)\tInt Array iaa = {", __LINE__);
for (i = 0; i < __NELE(iaa); i++)
{
printf(" %d,", iaa[i]);
}
printf(" }\n");
Note
  1. To connect to your project, you need to declare a one header file fswap.h
  2. If you use own structures in an array format, you will need to add their description to fswap.h
  3. All functions that are automatically selected by __swap_fast(A,B), do not use them directly.

Function Documentation

void __swap_p ( void *  a,
void *  b,
size_t  na,
size_t  nb 
)
inline

Swap all sized types.

Parameters
aany C types pointer, equals type b.
bany C types pointer, equals type a.
naswap size to a type.
nbswap size to b type.
See also
__swap_fast
Attention
  1. variable 'a' and 'b' must not be equal.
  2. variable 'na' and 'nb' must be equal.
  3. do not use this function directly.
void __swap_pp ( void **  a,
void **  b 
)
inline

Swap double pointers types.

Parameters
aany C types double pointer, equals type b.
bany C types double pointer, equals type a.
See also
__swap_fast
Attention
  1. variable 'a' and 'b' must not be equal.
  2. do not use this function directly.
void __swap_ppp ( void ***  a,
void ***  b 
)
inline

Swap triple pointers types.

Parameters
aany C types triple pointer, equals type b.
bany C types triple pointer, equals type a.
See also
__swap_fast
Attention
  1. variable 'a' and 'b' must not be equal.
  2. do not use this function directly.