diff --git a/c_modern_approach/Preprocessor/defined.c b/c_modern_approach/Preprocessor/defined.c new file mode 100644 index 0000000..a98f045 --- /dev/null +++ b/c_modern_approach/Preprocessor/defined.c @@ -0,0 +1,12 @@ +#include +#define DEBUG 1 + +int main() +{ + #if defined (DEBUG) + printf("DEBUG defined"); + #else + printf("DEBUG not defined"); + #endif + return 0; +} diff --git a/c_modern_approach/Preprocessor/error.c b/c_modern_approach/Preprocessor/error.c new file mode 100644 index 0000000..2cc6be1 --- /dev/null +++ b/c_modern_approach/Preprocessor/error.c @@ -0,0 +1,21 @@ +#include +// #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 + diff --git a/c_modern_approach/Preprocessor/ifdef_ifndef.c b/c_modern_approach/Preprocessor/ifdef_ifndef.c new file mode 100644 index 0000000..c27a89a --- /dev/null +++ b/c_modern_approach/Preprocessor/ifdef_ifndef.c @@ -0,0 +1,13 @@ +#include +// #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; +} diff --git a/c_modern_approach/Preprocessor/ifendif.c b/c_modern_approach/Preprocessor/ifendif.c new file mode 100644 index 0000000..d1653fe --- /dev/null +++ b/c_modern_approach/Preprocessor/ifendif.c @@ -0,0 +1,11 @@ +#include +#define DEBUG 0 + +int main() +{ + printf("Hello "); + #if DEBUG + printf("debug "); + #endif + printf("World!"); +} diff --git a/c_modern_approach/Preprocessor/pragma.c b/c_modern_approach/Preprocessor/pragma.c new file mode 100644 index 0000000..a0365ea --- /dev/null +++ b/c_modern_approach/Preprocessor/pragma.c @@ -0,0 +1,12 @@ +/* + * #pragma tokens + * Используется когда программы слишком большие и надо воспользоваться какими-то + * особыми фичами компилятора. + */ + +#include +#pragma data(heap_size = > 1000, stack_size = > 2000) +int main() +{ + return 0; +}