C/Macro Preprocessor/if def


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

#define and #ifdef

//file1.h
#define USD 1
//file2.h
#define UKP 1
//file3
#include <stdio.h>
#include <file1.h>
#if !defined (USD) || !defined (UKP)    
    #error "RROR: NO_CURRENCY rate is specified."
#endif
main() {    
    
  int rs;
  rs = 10 * currency_rate;
  printf ("d\n", rs);
}


#define, #ifdef #else example

#include <stdio.h>
#define TED 10
int main(void)
{
#ifdef TED
  printf("Hi Ted\n");
#else
  printf("Hi anyone\n");
#endif
#ifndef RALPH
  printf("RALPH not defined\n");
#endif
  return 0;
}


Simple #if/#else example

#include <stdio.h>
#define MAX 10
int main(void)
{
#if MAX>99
  printf("Compiled for array greater than 99.\n");
#else
  printf("Compiled for small array.\n");
#endif 
  return 0;
}


Simple #if example

#include <stdio.h>
#define MAX 100
int main(void)
{
#if MAX>99
  printf("Compiled for array greater than 99.\n");
#endif
  return 0;
}