C/Macro Preprocessor/Preprocessor IF

Материал из C\C++ эксперт
Перейти к: навигация, поиск

IF and endif preprocessor

#include <stdio.h>
#define TEST 29
#if defined TEST
int main(void) 
{
  printf("This is a test.\n");
  return 0;
}
#endif


ifdef preprocessor

#include <stdio.h>
#define DOG
int main(void)
{
#ifdef DOG
  printf("DOG is defined.\n");
#endif
#undef DOG
#ifdef DOG
  printf("This line is not compiled.\n");
#endif
  return 0;
}


#IF #ELSE #ENDIF

//file1.h
#define USD 1
//file2.h
#define UKP 1
//file3
#include <stdio.h>
#include <file1.h> 
#if (defined (USD))  
    #define currency_rate 46
#else
    #define currency_rate 100 
#endif 
main() {    
  int rs;
  rs = 10 * currency_rate;
  printf ("d\n", rs);
}