-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30d9c30
commit d8b84c3
Showing
5 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BINARY=swap_macro | ||
|
||
include ../../Makefile.exerc |
17 changes: 17 additions & 0 deletions
17
chapter_4.functions_progr_structure/4_14.swap_macro/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# include <stdio.h> | ||
# include "swap.h" | ||
|
||
int main () | ||
{ | ||
char c0 = '0', c1 = '1'; | ||
int i0 = 10, i1 = 222; | ||
|
||
printf("char: '%c', '%c' => '", c0, c1); | ||
swap(char, c0, c1); | ||
printf("%c', '%c'\n", c0, c1); | ||
printf("int: %d, %d => ", i0, i1); | ||
swap(int, i0, i1); | ||
printf("%d, %d\n", i0, i1); | ||
|
||
return 0; | ||
} |
11 changes: 11 additions & 0 deletions
11
chapter_4.functions_progr_structure/4_14.swap_macro/swap.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ifndef SWAP_H | ||
# define SWAP_H | ||
|
||
# define swap(T, X, Y) \ | ||
{ \ | ||
T c = X; \ | ||
X = Y; \ | ||
Y = c; \ | ||
}; \ | ||
|
||
# endif |
Empty file.
2 changes: 2 additions & 0 deletions
2
chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
char: '0', '1' => '1', '0' | ||
int: 10, 222 => 222, 10 |