Going thorugh preprocessor chapter

This commit is contained in:
pro100ton 2025-01-23 22:48:21 +03:00
parent 8bb4bc8a64
commit 84071736e2
7 changed files with 75 additions and 0 deletions

View 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;
}

View 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);
}

View 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");
* }
*/

View 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));
}

View 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);
}

View 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");
}
}

View file

@ -0,0 +1,2 @@
# Точка останова
Creating longer macros - 328