Going thorugh preprocessor chapter
This commit is contained in:
parent
8bb4bc8a64
commit
84071736e2
7 changed files with 75 additions and 0 deletions
17
c_modern_approach/Preprocessor/celcius.c
Normal file
17
c_modern_approach/Preprocessor/celcius.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "stdio.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define FREEZING_PT 32.0f
|
||||
#define SCALE_FACTOR (5.0f / 9.0f)
|
||||
|
||||
int main(void) {
|
||||
float farenheit, celsius;
|
||||
|
||||
printf("Enter Fahrenheit temperature: ");
|
||||
scanf("%f", &farenheit);
|
||||
|
||||
celsius = (farenheit - FREEZING_PT) * SCALE_FACTOR;
|
||||
|
||||
printf("Celcius equivalent is: %.1f\n", celsius);
|
||||
return 0;
|
||||
}
|
7
c_modern_approach/Preprocessor/double_hashtag_op.c
Normal file
7
c_modern_approach/Preprocessor/double_hashtag_op.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#define MK_ID(n) i##n
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int MK_ID(1); // This converts to `int i1`
|
||||
printf("%d", i1);
|
||||
}
|
21
c_modern_approach/Preprocessor/macro_rules.c
Normal file
21
c_modern_approach/Preprocessor/macro_rules.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#define SIZE 256
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int BUFFER_SIZE;
|
||||
if (BUFFER_SIZE > SIZE)
|
||||
puts("ERROR: SIZE exceeded");
|
||||
}
|
||||
|
||||
/*
|
||||
* Код выше трансформируется в следующее:
|
||||
*
|
||||
*
|
||||
* int main(int argc, char *argv[])
|
||||
* {
|
||||
* int BUFFER_SIZE;
|
||||
* if (BUFFER_SIZE > 256)
|
||||
* puts("ERROR: SIZE exceeded");
|
||||
* }
|
||||
*/
|
9
c_modern_approach/Preprocessor/parametrized_macroses.c
Normal file
9
c_modern_approach/Preprocessor/parametrized_macroses.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int j, k;
|
||||
j = 10;
|
||||
k = 20;
|
||||
printf("%d", MAX(j, k));
|
||||
}
|
9
c_modern_approach/Preprocessor/playground.c
Normal file
9
c_modern_approach/Preprocessor/playground.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#define PRINT_INT(n) printf(#n " AND " #n " = %d\n", n)
|
||||
|
||||
int main(void) {
|
||||
int i, j;
|
||||
i = 10;
|
||||
j = 20;
|
||||
PRINT_INT(i / j);
|
||||
}
|
10
c_modern_approach/Preprocessor/undef.c
Normal file
10
c_modern_approach/Preprocessor/undef.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#define SIZE 100
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
i = 101;
|
||||
#undef SIZE
|
||||
if (i > SIZE) {
|
||||
printf("Yey!\n");
|
||||
}
|
||||
}
|
2
c_modern_approach/README.md
Normal file
2
c_modern_approach/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Точка останова
|
||||
Creating longer macros - 328
|
Loading…
Reference in a new issue