vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

c_preprocessor_conditional.c (705B)


      1 // C preprocessor - conditional inclusion
      2 
      3 // Source: https://en.cppreference.com/w/c/preprocessor/conditional
      4 
      5 #define ABCD 2
      6 #include <stdio.h>
      7 
      8 int main(void)
      9 {
     10 
     11 #ifdef ABCD
     12     printf("1: yes\n");
     13 #else
     14     printf("1: no\n");
     15 #endif
     16 
     17 #ifndef ABCD
     18     printf("2: no1\n");
     19 #elif ABCD == 2
     20     printf("2: yes\n");
     21 #else
     22     printf("2: no2\n");
     23 #endif
     24 
     25 #if !defined(DCBA) && (ABCD < 2 * 4 - 3)
     26     printf("3: yes\n");
     27 #endif
     28 
     29 // C23 directives #elifdef/#elifndef
     30 #ifdef CPU
     31     printf("4: no1\n");
     32 #elifdef GPU
     33     printf("4: no2\n");
     34 #elifndef RAM
     35     printf("4: yes\n"); // selected in C23 mode, may be selected in pre-C23 mode
     36 #else
     37     printf("4: no3\n"); // may be selected in pre-C23 mode
     38 #endif
     39 }
     40