Finished preprocessor theory section

This commit is contained in:
t0xa 2025-10-17 20:52:54 +03:00
parent c564389e8b
commit b104a6f6cf
5 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,12 @@
#include <stdio.h>
#define DEBUG 1
int main()
{
#if defined (DEBUG)
printf("DEBUG defined");
#else
printf("DEBUG not defined");
#endif
return 0;
}

View file

@ -0,0 +1,21 @@
#include <stdio.h>
// #define DEBUG 1
int main() {
#ifdef DEBUG
printf("All good, DEBUG is initialized");
#else
#error Debug is not initiated!
#endif
return 0;
}
// #error identifier blocks code compilation if compiler reached it.
// For example code above will not compile if DEBUG is not initiated.
//
// error.c: In function main:
// error.c:8:2: error: #error Debug is not initiated!
// 8 | #error Debug is not initiated!
// | ^~~~~
// make: *** [Makefile:14: main] Error 1

View file

@ -0,0 +1,13 @@
#include <stdio.h>
// #define DEBUG 1
// #ifdef identifier is similar to #if defined(identifier)
//
// #ifndef is just opposite of #ifdef
int main() {
#ifdef DEBUG
printf("DEBUG defined!");
#else
printf("DEBUG NOT defined!");
#endif
return 0;
}

View file

@ -0,0 +1,11 @@
#include <stdio.h>
#define DEBUG 0
int main()
{
printf("Hello ");
#if DEBUG
printf("debug ");
#endif
printf("World!");
}

View file

@ -0,0 +1,12 @@
/*
* #pragma tokens
* Используется когда программы слишком большие и надо воспользоваться какими-то
* особыми фичами компилятора.
*/
#include <stdio.h>
#pragma data(heap_size = > 1000, stack_size = > 2000)
int main()
{
return 0;
}