Finished preprocessor theory section
This commit is contained in:
parent
c564389e8b
commit
b104a6f6cf
5 changed files with 69 additions and 0 deletions
12
c_modern_approach/Preprocessor/defined.c
Normal file
12
c_modern_approach/Preprocessor/defined.c
Normal 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;
|
||||
}
|
||||
21
c_modern_approach/Preprocessor/error.c
Normal file
21
c_modern_approach/Preprocessor/error.c
Normal 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
|
||||
|
||||
13
c_modern_approach/Preprocessor/ifdef_ifndef.c
Normal file
13
c_modern_approach/Preprocessor/ifdef_ifndef.c
Normal 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;
|
||||
}
|
||||
11
c_modern_approach/Preprocessor/ifendif.c
Normal file
11
c_modern_approach/Preprocessor/ifendif.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#define DEBUG 0
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello ");
|
||||
#if DEBUG
|
||||
printf("debug ");
|
||||
#endif
|
||||
printf("World!");
|
||||
}
|
||||
12
c_modern_approach/Preprocessor/pragma.c
Normal file
12
c_modern_approach/Preprocessor/pragma.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* #pragma tokens
|
||||
* Используется когда программы слишком большие и надо воспользоваться какими-то
|
||||
* особыми фичами компилятора.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#pragma data(heap_size = > 1000, stack_size = > 2000)
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue