Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Generic-swap/C/generic-swap-1.c
Normal file
6
Task/Generic-swap/C/generic-swap-1.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
void swap(void *va, void *vb, size_t s)
|
||||
{
|
||||
char t, *a = (char*)va, *b = (char*)vb;
|
||||
while(s--)
|
||||
t = a[s], a[s] = b[s], b[s] = t;
|
||||
}
|
||||
1
Task/Generic-swap/C/generic-swap-2.c
Normal file
1
Task/Generic-swap/C/generic-swap-2.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
#define Swap(X,Y) do{ __typeof__ (X) _T = X; X = Y; Y = _T; }while(0)
|
||||
32
Task/Generic-swap/C/generic-swap-3.c
Normal file
32
Task/Generic-swap/C/generic-swap-3.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define Swap(X,Y) do{ __typeof__ (X) _T = X; X = Y; Y = _T; }while(0)
|
||||
|
||||
struct test
|
||||
{
|
||||
int a, b, c;
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
struct test t = { 1, 2, 3 };
|
||||
struct test h = { 4, 5, 6 };
|
||||
double alfa = 0.45, omega = 9.98;
|
||||
|
||||
struct test *pt = &t;
|
||||
struct test *th = &h;
|
||||
|
||||
printf("%d %d %d\n", t.a, t.b, t.c );
|
||||
Swap(t, h);
|
||||
printf("%d %d %d\n", t.a, t.b, t.c );
|
||||
printf("%d %d %d\n", h.a, h.b, h.c );
|
||||
|
||||
printf("%lf\n", alfa);
|
||||
Swap(alfa, omega);
|
||||
printf("%lf\n", alfa);
|
||||
|
||||
printf("%d\n", pt->a);
|
||||
Swap(pt, th);
|
||||
printf("%d\n", pt->a);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue